Reputation: 44114
If I have this entity:
@Entity
class Pet {
@Id
long id;
public enum State { ALIVE, DEAD }
@Enumerated(EnumType.STRING)
@...
State state;
@...
String name;
}
Can I create a mapping like this:
@Entity
class Owner {
@OneToMany(condition="state = ALIVE") // or something like that
Set<Pet> alivePets;
@OneToMany(condition="state = DEAD")
Set<Pet> deadPets;
}
Upvotes: 36
Views: 31158
Reputation: 6685
As far as I know this is not part of the JPA spec. At least Hibernates JPA implementation provides an own annotation @Where
which can be used:
@OneToMany
@Where(clause = "state = 'ALIVE'")
Set<Pet> alivePets
Upvotes: 52