问题描述
我有一个 Item
POJO,它包含一个设置由标签组成的< String>
。标签包含在另一个数据库表中,这些表来自 Item
表,所以我做了一个连接来填充pojo。
我试图从书籍Java Persistence with Hibernate中运行一个简单的示例查询,其中我从Item item中的'hello'成员查询,其中item.labels
的成员。只是,出于某种原因,我得到了一个
`org.hibernate.hql.ast.QuerySyntaxException:意外的子树结束[from / *合格的类路径* /。项目项目'hello'成员的item.labels]`
以下是我的POJO:
public class Item
private int uuid;
private Set< String> labels = new HashSet< String>();
@Id
public int getUuid(){
return uuid;
$ b @CollectionOfElements
@JoinTable(name =labels,joinColumns = @ JoinColumn(name =uuid))
@Column(name =标签)
public Set< String> getLabels(){
返回标签;
}
}
原始资源集合,您应该使用如下所示的HQL查询:
from item item join item.labels lbls'hello'in(lbls)
PS:'join'是必需的,因为'labels'是OneToMany或ManyToMany变体,因为括号是必需的'lbls'是一个集合
I'm a newbie to Hibernate.
I have an Item
POJO which contains a Set<String>
consisting of labels. The labels are contained on another Database table from the Item
table, so I do a join to populate the pojo.
I'm trying to run a simple example query from the book "Java Persistance with Hibernate" where I query from Item item where 'hello' member of item.labels
. Only, for some reason I am getting a
`org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree[from /*qualified class path*/.Item item where 'hello' member of item.labels]`
What might be causing this issue?
Here are my POJOs:
public class Item
private int uuid;
private Set<String>labels = new HashSet<String>();
@Id
public int getUuid(){
return uuid;
}
@CollectionOfElements
@JoinTable(name="labels", joinColumns=@JoinColumn(name="uuid"))
@Column(name="label")
public Set<String> getLabels(){
return labels;
}
}
For primitives collections you should use HQL query like this:
from Item item join item.labels lbls where 'hello' in (lbls)
PS: 'join' is required because 'labels' is OneToMany or ManyToMany variant, parentheses are required because 'lbls' is a collection
这篇关于休眠和意外的Subtree异常结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!