Need help On hibernate


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.

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++) {
	Map<String, String> map = null;
	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.

DocumentName is 14_gm.gif
DocumentName is 14_gm.gif
DocumentName is 14_gm.gif
DocumentName is 14_gm.gif
DocumentName is 14_gm.gif
DocumentName is 14_gm.gif


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.


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


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:

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


When i am getting error with “”, please check the image attached. how and to get the values from that object.


while i am executing that code i am getting this error as well.


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.


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


If you read the User Guide, you will know how to fix more than this issue.