Hibernate QuerySyntaxException

时间:2012-04-23 10:58:20

标签: java hibernate jpa

我有两个名为Batch和Position的类,我有这个错误

Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [from bean.Position p where :batch member of p.positionConstraint]

调用方法findByStudent时。我也在使用JPA,如果有帮助的话。非常感谢

public  class  Position {  
@ElementCollection
@LazyCollection(LazyCollectionOption.FALSE)  
@CollectionTable(name = "position_constraint")  
private  List<Batch> positionConstraint;  
}


public  class  Batch {
private  College college;

private  YearLevel yearLevel;

@Override
public  List<Position> findByStudent(StudentInformation student) {  
Batch batch = new  Batch(student.getCollege(), student.getYearLevel());  

Query query = getEntityManager().createQuery(
"from Position p where :batch member of p.positionConstraint").setParameter("batch", batch);  
return query.getResultList();  
}

2 个答案:

答案 0 :(得分:3)

我认为你的字符串中有错误。它应该是: "from Position p where :batch member of p.positionConstraint"

答案 1 :(得分:0)

您的示例适用于Hibernate 3.6.8.Final和数据库H2 1.3.160的组合。还有JPA等效查询:

select from Position p where :batch member of p.positionConstraint

根据您使用的Hibernate版本,可能是您遇到此错误:HHH-5209,它仍处于打开状态。另外HHH-5173提供了一些补充说明。