JPA OneToMany集合的条件

9 浏览
0 Comments

JPA OneToMany集合的条件

如果我有这个实体:

@Entity
class Pet {
    @Id
    long id;
    public enum State { ALIVE, DEAD }
    @Enumerated(EnumType.STRING)
    @...
    State state;
    @...
    String name;
}

我能创建这样的映射吗:

@Entity
class Owner {
    @OneToMany(condition="state = ALIVE") // 或者类似的条件
    Set alivePets;
    @OneToMany(condition="state = DEAD")
    Set deadPets;
}

0