Author: robbin a lot of people do not know how to obtain HQL return value, for example the following description: Take a single field, the field will return List:
Java code:
1 query q = s.
CREATEQUERY
"" SELECT C.
ID from cat as c "
);
2
List l = Q.
List
(
);
3
for
(i =
0; i Size ( ); i ) { 4 Long id = ( Long ) L. get (i ); 5 SYSTEM. OUT. PRINTLN (ID. LongValue ( ) ); 6 } Take multiple fields, Hibernate makes each ID and name a single-dimensional array of 2 elements, and the List is actually a collection of single-dimensional array. Java code: 1 query q = s. CREATEQUERY "" SELECT CAT. ID, CAT. Name, from cat " ); 2 List l = Q. List ( ); 3 for ( INT i = 0; i Size ( ); i ) { ...} 4 Object [ ] ROW = ( Object [ ] ) L. get (i ); 5 Long id = ( Long Row [ 0 ]; 6 String name = ( String Row [ 1 ]; Seduce } In this case, HQL does not construct PO, this is easy to verify. JCS is an object cache. If you write such an HQL, JCS is empty, indicating that Hibernate does not construct PO, if you add an object C itself, the JCS has data, as follows: Java code: 1 query q = s. CREATEQUERY "" SELECT C. ID, C. Name, c from cat as c " ); 2 List l = Q. List ( ); 3 for ( INT i = 0; i Size ( ); i ) { ...} 4 Object [ ] ROW = ( Object [ ] ) L. get (i ); 5 Long id = ( Long Row [ 0 ]; 6 String name = ( String Row [ 1 ]; 7 Cat C = (Cat Row [ 2 ]; 8 } Ezerg Programming