Naveen
November 24, 2018, 7:18pm
1
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++) {
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.
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
vlad
November 24, 2018, 7:33pm
2
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.
Naveen
November 24, 2018, 7:47pm
3
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
vlad
November 24, 2018, 8:06pm
4
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")
.getResultList();
for(ColumnDetails columnDetails : demoEntitities) {
log.info("ColumnDetails: {}", columnDetails);
}
Naveen
November 25, 2018, 8:17am
5
When i am getting error with “log.info”, please check the image attached. how and to get the values from that object.
Naveen
November 25, 2018, 8:24am
6
while i am executing that code i am getting this error as well.
vlad
November 25, 2018, 8:44am
7
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.
Naveen
November 25, 2018, 10:54am
8
Can you explain in detail so that i will resolve the issue
vlad
November 25, 2018, 11:22am
9
If you read the User Guide , you will know how to fix more than this issue.