Query Language Hibernate , grammar with SQL basically the same, but the attributes of the entity classes and where, rather than table names and column names of the table
statement
Query query = session.createQery(String hql);
Inquire
list
Returns the List Object
List<POJO> list = query.list();
iterate
Return Iterator objects
Iterator<POJO> it = query.iterate();
list and iterate difference
list will be all-time query results.
iterate a one-off query all primary key, and call iterator.next () priority querying the primary key of the corresponding record cache when.
iterate will make better use of cache.
select
When selecting a plurality of columns returned List <Object []> List
Placeholder
?
And PreparedStatement like, you can use placeholders '?'
Provided placeholder value : query.setType (index, value); // index from 0 Start
Use the name
You need to be set in place of the placeholder ': placeholder name '
Set the value of placeholder name : query.setType ( " placeholder name ", value);
Urgent connection
Use join , only when specific attributes to call multi-party entities will really be the result of the query.
Connection may be used within a disposable urgent Remove all objects
In join after adding fetch Keywords
Named HQL
Configuration
You can be defined in the configuration file HQL after the code calls
<query name="命名">
<! [CDATA [HQL statement ]] >
</query>
transfer
Query query = session.getNameQuery("命名");