2019独角兽企业重金招聘Python工程师标准>>>
Person类中包含有MyEvent这个类
public class Person{private Long id;private String name;private MyEvent myEvent;
}
一、HQL from语句
1、结果类型:List<Person>
from Person 或者 from Person as p
from Person as p where p.myEvent.title = :title
注意:hibernate3.2.3之前总是对的。 hibernate3.2.3之后如果myEvent是普通属性或关联的实体也是对的,如果myEvent是一个集合会出异常 因此hibernate推荐使用下面的方式:
select p from Person as p inner join p.myEvent as e where e.title = :title
2、结果类型 List<Person,Event>
from Person as p inner join p.myEvent as event where event.title = : title
注:查询出来是:是一个集合,集合元素是Person,myEvent组成的数组。 结果类型: List<Person,Event>
from Person as p left outer join p.myEvent as event where event.title = : title
注意:查询出来是:是一个集合,集合元素是Person,myEvent组成的数组。
结果类型: List<Person,Event>
from Person as p right outer join p.myEvent as event where event.title = : title
from Person as p full join p.myEvent as event where event.title = : title
第二:HQL select语句
1、结果类型: List<String>
select p.name from Person as p
2、结果类型:List<Object[String,Person]>
select p.name,p from Person as p
3、结果类型:List<String,String>
select new List(p.name,p.address) from Person as p
4、结果类型:List<ClassTest>
select new ClassTest(p.name,p.address) from Person as p
注意:前提ClassTest 类有两个参数的构造器。
5、结果类型:List<map<String,String>>
select new map(p.name as personName) from Person as p