【发布时间】:2016-03-24 14:56:23
【问题描述】:
为简单起见,这里是我的模型的较小版本:
@Entity
public class Request {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Enumerated(EnumType.STRING)
private EntityType entityType; //Differentiator
private String entityId; //The identity of the column it refers to.
private Timestamp date = new Timestamp(System.currentTimeMillis());
public enum EntityType {
TypeOfRequestObject, AnotherType, Unknown
}
}
现在,使用 JPA,我提出了一些允许我访问数据的查询,但它很难看并且有些硬编码,我更喜欢的是类似于 ManyToOne/OneToMany 注释中的 Where 查询的内容也将允许级联。
@ManyToOne(where="entityType='AnotherType'")
你们听说过这样的事吗? 我可以理解 ManyToOne 可能不是正确的方法。
我正在使用标准的 Hibernate 5、JPA 和 Spring Boot,所有这些都是通过 Jackson 消息转换器请求的。
谢谢
【问题讨论】:
标签: java spring hibernate jpa orm