Bar*_*lom 21 java hibernate jpa
如果我有这个实体:
@Entity
class Pet {
@Id
long id;
public enum State { ALIVE, DEAD }
@Enumerated(EnumType.STRING)
@...
State state;
@...
String name;
}
Run Code Online (Sandbox Code Playgroud)
我可以创建这样的映射:
@Entity
class Owner {
@OneToMany(condition="state = ALIVE") // or something like that
Set<Pet> alivePets;
@OneToMany(condition="state = DEAD")
Set<Pet> deadPets;
}
Run Code Online (Sandbox Code Playgroud)
mag*_*omi 30
据我所知,这不是JPA规范的一部分.至少Hibernates JPA实现提供了一个@Where可以使用的自己的注释:
@OneToMany
@Where(clause = "state = 'ALIVE'")
Set<Pet> alivePets
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17380 次 |
| 最近记录: |