hibernate的hql查询直接返回java对象时出现问题3
向大家请教一个问题,现在有三张表,表之间没有关联,我需要将三张表里面的所有东西查询出来存储到一个新的对象中,该如何实现,使用hibernate.
在hibernate里面有这样一个使用介绍
select new Family(mother, mate, offspr)
from DomesticCat as mother
join mother.mate as mate
left join mother.kittens as offspr
但为什么new Family总是不起作用?找不到该类
问题补充:
根据你的修改,修改后出现了新问题
20:11:05,234 ERROR org.hibernate.hql.PARSER: Unable to locate appropriate constructor on class [com.biokee.biap.sys.model.VUserLog]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.biokee.biap.sys.model.VUserLog]
在hibernate里面有这样一个使用介绍
select new Family(mother, mate, offspr)
from DomesticCat as mother
join mother.mate as mate
left join mother.kittens as offspr
但为什么new Family总是不起作用?找不到该类
问题补充:
根据你的修改,修改后出现了新问题
20:11:05,234 ERROR org.hibernate.hql.PARSER: Unable to locate appropriate constructor on class [com.biokee.biap.sys.model.VUserLog]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.biokee.biap.sys.model.VUserLog]
解决办法
Family应该有一个构造函数:
public class Family{
public Family(){}
public Family(Mother m, Mate m, offspr){
...
}
}