Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query Difference?

 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you look at the values in the debugger ?
did you loop over the arrays ?

pascal
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic