1:hibernate queries with a deeper query, using detachedcriteria multiple table queries.
There are two table Clazz,user in the database, because it is a test program, the foreign key is not set, and the associated attribute between two objects is not included in the mapping file, such as <many-to-one>
It's just that when you write an hql, you implement an association between two objects, similar to the
Sql:select c.id,c.name,c.age,u.name from Clazz p,user u where C.rid = u.id where c.age = and u.name= ' Kevin '
Workaround:
1. Create Detachedcriteria
The call CreateAlias method CreateAlias is mainly used for querying, establishing a relationship between two tables, and querying data related to two tables.
Detachedcriteria Personcriteria = Detachedcriteria.forclass (Clazz.class);
Gethibernatetemplate (). Findbycriteria (Personcriteria.add (Restrictions.eq ("Age", new Integer). CreateAlias (" User "," U "). Add (Restrictions.eq (" U.name "," Kevin "));
2. Establish an association relationship
Use Detachedcriteria multiple table queries must decide to include in the person object's mapping file:
<many-to-one name= "Room" cascade= "All" class= "Hamob". Room "column=" rid "/>