When using hibernate SQL queries in multi-table queries, the object[] array is generally returned, or you can use the
Session.createsqlquery (SQL). Setresulttransformer (Transformers.alias_to_entity_map);
To map for processing, you can turn query results into entity classes in the following ways:
1,sql statement String sql= "select S.id as id,s.classname as classname from grade S,student St where S.id=st.classid"
Use the following statement
Session.createsqlquery (SQL). Setresulttransformer (Transformers.aliastobean (Grade.class)) You can convert the fields queried in SQL into class, but you must specify an alias for each field, which is the corresponding attribute in class class, but be aware that each column must be addscalar ("column name"). If you do not set the Addscalar method, you may be able to report an exception for a transformation error. If the query results include fields from multiple tables and cannot be accepted for an entity class, create a new entity class that corresponds to the query result, or use the map result set directly
2,sql statement String sql= "SELECT {s.*} from grade S,student St where S.id=st.classid"
SQL that is queried for all of these fields can be converted to entity classes using addentity
SQLQuery query=session.createsqlquery (SQL);
Query.addentity ("s", Grade.class);
SQL query statement with a placeholder that allows hibernate to use the alias of the field.
The query returns an alias for the entity, and its SQL table.
The Addentity () method ties the alias of the SQL table to the entity class and determines the pattern of the query result set.
This allows you to assign the values of all the fields in the class table to the class Java training organization ranking , and must be all attributes
3,sql statement String sql= "SELECT {s.*},{st.*} from grade S,student St where S.id=st.classid"
SQLQuery query=session.createsqlquery (SQL);
Query.addentity ("s", Grade.class);
Query.addentity ("St", Student.class);
Using such a query to get a object[] array, object[0] is the class entity class, Object[1] is the student entity class
You can use the Addscalar (String arg,type type) method to define the type of field to return, such as
S.createsqlquery (SHUIQINGHQL). Addscalar ("Stcd", hibernate.string). Addscalar ("STNM")
Hibernate SQL queries converted to entity classes