OpenJPA,如何将多个LEFT JOIN FETCH转换为JPA符合声明?

时间:2017-11-17 13:14:41

标签: java jpa join fetch jpql

由于从Hibernate迁移到OpenJPA,我必须修改以下多左连接提取语句:

SELECT distinct aaa 
    FROM ClassA aaa 
    left join fetch aaa.classBs bbb 
    left join fetch bbb.classC ccc 
    where aaa.id = ?1

OpenJPA抛出此异常:

<openjpa-2.4.0-r422266:1674604 nonfatal user error> 
org.apache.openjpa.persistence.ArgumentException: "Encountered "bbb" at character 85, but expected: [",", ".", "GROUP", "HAVING", "INNER", "JOIN", "LEFT", "ORDER", "WHERE", <EOF>]." while parsing JPQL "SELECT distinct aaa FROM ClassA aaa left join fetch aaa.classBs bbb left join fetch bbb.classC ccc where aaa.id = ?1".

ClassA的:

@Entity
@Table(name = "TABLE_A")
public class ClassA {
    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "classA")
    private Set<ClassB> classBs;    
}

ClassB的:

 @Entity
 @Table(name = "TABLE_B")
 public class ClassB {
    @ManyToOne
    @JoinColumn(name = "CLASSC_ID")
    private ClassC classC;

    @ManyToOne
    @JoinColumn(name = "CLASSA_ID")
    private ClassA classA;
}

ClassC:

@Entity
@Table(name = "CLASS_C")
public class ClassC {
    @Column(name = "NAME")
    private String name;
}

似乎第二次左连接提取会导致问题。

我们非常感谢任何建议。 提前致谢, 托马斯

0 个答案:

没有答案