Atitit. The ORM Framework hibernate uses sqlquery createsqlquery addentity
1. addentity
to nativeSQLthe control of query execution is throughsqlqueryinterface, by executing theSession.Createsqlquery ()gets the interface. In the simplest case, we can take the following form:
List cats = Sess.createsqlquery ("Select * from Cats"). Addentity (Cat. Class). list ();
Author :: Old Wow's paw attilax ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
2. Addentity placeholder Aliases
Here, the result set field name is assumed to be the same as the field name indicated in the mapping file. For queries that have multiple tables connected, this can cause problems because fields with the same name may appear in more than one table. The following method avoids the problem of duplicate field names :
List cats = Sess.createsqlquery ("Select {cat.*} from Cats Cat"). Addentity ("Cat", Cat. Class). list ();
This query specifies the following:
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.
3. AddJoin ()methods can be used to load the associations of other entities and collections.
List cats = Sess.createsqlquery (
"Select {cat.*}, {kitten.*} from Cats cat, cats kitten where kitten.mother = Cat.id")
. Addentity ("Cat", Cat. Class)
. AddJoin ("Kitten", "Cat.kittens")
. List ();
4. Reference
Hibernate in createsqlquery addentity () and Setresulttransformer () method - The rookie of Daniel -Iteye technology website . htm
Atitit. The ORM Framework hibernate uses sqlquery createsqlquery addentity