# Need help On hibernate

**URL:** <https://discourse.hibernate.org/t/need-help-on-hibernate/1786>\
**Category:** Hibernate ORM\
**Created:** [November 24, 2018, 7:18pm UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786 "2018-11-24T19:18:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.hibernate.org/u/Naveen)\
**Post date:** [November 24, 2018, 7:18pm UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/1 "2018-11-24T19:18:51Z")

</div>

I am running the below code using the query but the problem here is it is fetching the total count(Number of records in a table) but if i am printing the result it giving the same output.

```auto
List<ColumnDetails> demoEntitities = (List<ColumnDetails>)session.createQuery("from ColumnDetails where ParentID = '28948811' and TRUNC(ModifyDate) = TRUNC (SYSDATE)-1").list();
		   
for(int j=0; j<demoEntitities.size(); j++) {
System.out.println("Wsw");
	Map<String, String> map = null;
	demoEntitities.get(j);
	//System.out.println(list.get(j));
	map = (Map<String, String>) demoEntitities.get(j);
	String NodeID = String.valueOf(map.get("DataID"));
	String NameOfTheDocument = String.valueOf(map.get("Name"));
	//System.out.println("NodeID is " +NodeID);
	System.out.println("DocumentName is " +NameOfTheDocument);
}

```

for the above query result : getting count as 66 (correct)  
The below output getting for 66 times.

```auto
DocumentName is 14_gm.gif
Wsw
DocumentName is 14_gm.gif
Wsw
DocumentName is 14_gm.gif
Wsw
DocumentName is 14_gm.gif
Wsw
DocumentName is 14_gm.gif
Wsw
DocumentName is 14_gm.gif

```

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [November 24, 2018, 7:33pm UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/2 "2018-11-24T19:33:38Z")

</div>

It’s not clear what you are asking. Why do you mean by `count(Number of records in a table)`? There’s no count query. You are just selecting some entities.

Try to read your post from the perspective of someone who has no idea what you are doing and change it to be clear.

---

<div class="post-metadata">

**Author:** ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.hibernate.org/u/Naveen)\
**Post date:** [November 24, 2018, 7:47pm UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/3 "2018-11-24T19:47:47Z")

</div>

The total records in the table is 66.

When I am fetching those 66 records it’s giving me the same result.  
If it is not clear let me know so that I will explain in clear

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [November 24, 2018, 8:06pm UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/4 "2018-11-24T20:06:30Z")

</div>

The whole code does not make any sense.

```
Map<String, String> map = null; //That's useless.
demoEntitities.get(j); //That's even more useless.

```

Now, here comes the impossible part:

```
 map = (Map<String, String>) demoEntitities.get(j);

```

How can the `demoEntitities` List contains `Map` entries? You declared it as `List<ColumnDetails>`.

```
System.out.println("DocumentName is " +NameOfTheDocument);

```

You should use a Logging framework even for simple tests like this one.

Just override `toString` in `ColumnDetails` and you can rewrite your test case like this:

```auto
List<ColumnDetails> demoEntitities = (List<ColumnDetails>) session.createQuery(
	"from ColumnDetails where ParentID = '28948811' and TRUNC(ModifyDate) = TRUNC (SYSDATE)-1")
.getResultList();
		   
for(ColumnDetails columnDetails : demoEntitities) {
	log.info("ColumnDetails: {}", columnDetails);
}

```

---

<div class="post-metadata">

**Author:** ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.hibernate.org/u/Naveen)\
**Post date:** [November 25, 2018, 8:17am UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/5 "2018-11-25T08:17:15Z")

</div>

When i am getting error with “log.info”, please check the image attached. how and to get the values from that object. ![error](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/hibernate/original/1X/2dd01fe4f71a2fa5903503dfb4457a6e9ecebaf5.png)

---

<div class="post-metadata">

**Author:** ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.hibernate.org/u/Naveen)\
**Post date:** [November 25, 2018, 8:24am UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/6 "2018-11-25T08:24:05Z")

</div>

while i am executing that code i am getting this error as well. ![error1](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/hibernate/original/1X/8da3995667eafaa174725d43dbfb840db1796275.png)

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [November 25, 2018, 8:44am UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/7 "2018-11-25T08:44:27Z")

</div>

Either you upgrade to Hibernate 5.3 or you just use the Hibernate `Query` interface instead of the JPA one from the javax.persistence package.

---

<div class="post-metadata">

**Author:** ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.hibernate.org/u/Naveen)\
**Post date:** [November 25, 2018, 10:54am UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/8 "2018-11-25T10:54:47Z")

</div>

Can you explain in detail so that i will resolve the issue

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [November 25, 2018, 11:22am UTC](https://discourse.hibernate.org/t/need-help-on-hibernate/1786/9 "2018-11-25T11:22:52Z")

</div>

If you read the [User Guide](http://docs.jboss.org/hibernate/orm/5.3/userguide/html_single/Hibernate_User_Guide.html), you will know how to fix more than this issue.
