Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate QuerySyntaxException_Java_Hibernate_Jpa - Fatal编程技术网

Java Hibernate QuerySyntaxException

Java Hibernate QuerySyntaxException,java,hibernate,jpa,Java,Hibernate,Jpa,我有两个类叫做Batch和Position,我有这个错误 原因:org.hibernate.hql.ast.QuerySyntaxException:子树的意外结尾[来自bean.Position p其中:p.positionConstraint的批处理成员] 调用findByStudent方法时。如果有帮助的话,我也在使用JPA。非常感谢 public class Position { @ElementCollection @LazyCollection(LazyCollectionO

我有两个类叫做Batch和Position,我有这个错误

原因:org.hibernate.hql.ast.QuerySyntaxException:子树的意外结尾[来自bean.Position p其中: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();  
}
公共类位置{
@元素集合
@LazyCollection(LazyCollectionOption.FALSE)
@CollectionTable(name=“位置约束”)
私有列表位置约束;
}
公共类批处理{
私立学院;
私人年度一级年度一级;
@凌驾
公共列表查找学生(学生信息学生){
批处理批处理=新批处理(student.getCollege(),student.getYearLevel());
Query Query=getEntityManager().createQuery(
“从位置p开始,其中:p.positionConstraint的批次成员”).setParameter(“批次”,批次);
返回query.getResultList();
}

我想您的字符串中有一个错误。应该是:
“来自位置p,其中:p.positionConstraint的批处理成员”

我认为您的字符串中有一个错误。它应该是:
“来自位置p,其中:p.positionConstraint的批处理成员”

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

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

根据您使用的Hibernate版本的不同,可能是您面临的错误:,该错误仍然存在。还提供了一些额外的解释。

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

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

根据您使用的Hibernate版本的不同,可能是您面临的错误:,该错误仍然存在。还提供了一些额外的解释。

@Stephen C抱歉,它仍然不起作用。我更新了主要问题,以防万一。@Louieansong您还可以检查集合是否为空吗(不是空的,我在网上看到了一些迹象,这可能是造成问题的原因).@BorisStrandjev如果这是问题所在,它不应该有一个空指针异常吗?我确信集合不是空的。@Stephen C抱歉,它仍然不起作用。我更新了主要问题以防万一。@Louieansong你能检查集合不是空的吗(而且不是空的,我在网上看到了一些迹象,这可能是导致问题的原因)。@BorisStrandjev如果这是问题所在,它不应该有一个空指针异常吗?我确信集合不是空的。