相关疑难解决方法(0)

有关实体层次结构的JPA2标准查询

假设我具有以下实体域:

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE")
public abstract class Entity1 {
//some attributes
}

@Entity 
@DiscriminatorValue("T1")
public class Entity2 extends Entity1 {
    @OneToMany(fetch=FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy="parent")
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private Set<Entity1Detail> details = new HashSet<Entity1Detail>();
}

@Entity
public class Entity1Detail {
    @ManyToOne
    @JoinColumn(name="REF")
    private Entity2 parent;

    @Basic
    private Integer quantity;
}

@Entity
@DiscriminatorValue("T2")
public class Entity3 extends Entity1 {
//some other attributes
}
Run Code Online (Sandbox Code Playgroud)

当我执行JPQL查询时:

select e from Entity1 e left join e.details d where d.quantity > 1
Run Code Online (Sandbox Code Playgroud)

它运行良好(左联接; P)。但是,当我尝试使用JPA2标准API构建相同的查询时:

CriteriaBuilder builder …
Run Code Online (Sandbox Code Playgroud)

jpa-2.0

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

jpa-2.0 ×1