2012-04-23 79 views
0

我有两个类称为批处理中的地位与调用方法findByStudent当我有这个错误休眠QuerySyntaxException

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

。如果有帮助,我也使用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(); 
} 

回答

3

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

+0

我用批次替换了批量,仍然不起作用 – louieansonng 2012-04-23 11:20:21

+0

@louieansonng - 再次阅读答案。小心。 – 2012-04-23 11:25:27

+0

@Stephen C对不起,它仍然不起作用。我更新了主要问题以防万一。 – louieansonng 2012-04-23 11:29:47

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提供了一些额外的解释。

+0

我尝试使用3.6.8,它仍然无法正常工作... – louieansonng 2012-04-25 05:22:18