Hibernate的HQL语言类似于SQL语言,更适合于Java面向对象的思想. 类与数据库映射好了,不必考虑数据库.
实现Class1的表与Class2的表的联合查询:
Class1的class2属性外键到Class2.
String hql = "SELECT new {package name}.{[email protected]}(*, *, *) from Class1 as c1, Class2 as c2 where c1.class2 = c2"; //将查询结果封装到新的类中.
List<[email protected]> list = null; //定义要放的list.
Query query = session.create(hql);
list = query.list();
时间: 2024-12-13 05:53:03