aspose file tools
The moose likes Object Relational Mapping and the fly likes Query Difference? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Query Difference?" Watch "Query Difference?" New topic
Author

Query Difference?

Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Pls tell me the difference between two queries

Purpose: To select all the fields from AuditFindigns
1.Query query = session.createQuery("from Auditfinding af ");

System.out.println("select =>"+usrlist.toString());
==========================================
the output is:
==========================================
select =>[com.lib.Auditfinding@276, com.lib.Auditfinding@277,
com.lib.Auditfinding@278, com.lib.Auditfinding@279]
==========================================

Using the above list i can use display tag. sorting and pagination working fine.

But
Purpose : To select the particular Fields from AuditFinding
2. Query query = session.createQuery("select af.id,af.shipname from Auditfinding af ");
System.out.println("select =>"+usrlist.toString());
==========================================
the output is:
==========================================
select =>[[Ljava.lang.Object;@3c0007, [Ljava.lang.Object;@125fefa, [Ljava.lang.Object;@186df0f, [Ljava.lang.Object;@19e8f17]

Pls tell me the difference between two queries


Thank You<br />Edward
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
did you look at the values in the debugger ?
did you loop over the arrays ?

pascal
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 504

As you can see, the first one is list of auditfinding objects whereas the second one is a list of object[][] arrays of type Integer or Long(id) and String(shipname).


If you are not laughing at yourself, then you just didn't get the joke.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16622

Yes, in hibernate when you do a "projection" query, where you specify the fields in the Select portion, then Hibernate will return an Object[] array instead of instances of the object.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
IntelliJ Java IDE
 
subject: Query Difference?
 
Threads others viewed
Dynamic Column List?
Display Tag Probs using Struts with Hibernate?
Data retrivel from DB using Hibernate
Difference between createQuery and createSQLQuery?
get whole table from database
MyEclipse, The Clear Choice