Java 在hql中使用POJO
是否可以从一个hql语句中使用多个POJO或POJO与另一段数据的组合? 例如: 如果我有Foo类:Java 在hql中使用POJO,java,hibernate,hql,Java,Hibernate,Hql,是否可以从一个hql语句中使用多个POJO或POJO与另一段数据的组合? 例如: 如果我有Foo类: public class Foo { private String name; private String type; public Foo (String name, String type) { this.name = name; this.type = type; } } 和实体栏: @Entity public class Bar {
public class Foo {
private String name;
private String type;
public Foo (String name, String type) {
this.name = name;
this.type = type;
}
}
和实体栏:
@Entity
public class Bar {
private Long id;
private String name;
private String type;
...
}
以下hql将不会编译:
select bar.id, new Foo(bar.name, bar.type) from Bar bar
就这点而言,这个hql也不编译
select new list(bar.id, new Foo(bar.name, bar.type)) from Bar bar
这样行吗
谢谢
Netta你能添加你得到的编译错误吗?基本上是说你的查询有问题。是的,但是如果有实际的错误来看看有什么问题就好了。此外,如果此查询位于字符串中,则不会出现编译错误,但会出现运行时错误(执行时)是的,这是一个运行时错误,基本上表明您的查询有问题。此异常:由:org.hibernate.hibernateeexception引起:命名查询中的错误。。。