休眠和意外的Subtree异常结束 [英] Hibernate and Unexpected end of Subtree exception

查看:86
本文介绍了休眠和意外的Subtree异常结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个 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异常结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆