Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Hibernate

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code Segment that always executes Succesfully

String d="select HistAt as HistAt,RId as RId from tblrecord";
SQLQuery q=session.createSQLQuery(d);
q.addScalar("HistAt",Hibernate.STRING);
q.addScalar("RId",Hibernate.STRING);
List results=q.list();int i=0;

Pls how do i retrieve the results from the List
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When hibernate invokes a sql query, it returns a collection from the list() method.

this collection will contain an array of objects, the size of the array of objects will be the number of bound scalar parameterss you have defined (in your case, 2)

the following code snippet is what i use to unroll the list of array of objects into a different collection, it is a collection that is useful by me.



you can also see i was using debug statements to figure out what class types were being returned from the elements inside the array of objects from the sql query scalars. this will be what ever type they are mapped as in hibernate, in my case they were String.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic