aspose file tools*
The moose likes Object Relational Mapping and the fly likes Problem with Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with Hibernate" Watch "Problem with Hibernate" New topic
Author

Problem with Hibernate

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
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

Joined: Jun 06, 2006
Posts: 161
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.


Error: Keyboard not attached. Press F1 to continue.
 
 
subject: Problem with Hibernate