Spring,Hibernate,JPA,ManyToOne添加了where子句或Differentiator列而没有inhertiance

时间:2016-03-24 14:56:24

标签: java spring hibernate jpa orm

为简单起见,这是我的模型的较小版本:

@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我已经提出了一些允许我访问数据的查询,但它很丑陋且有些硬编码,我更喜欢的是Where Query in ManyToOne / OneToMany注释也允许级联。

@ManyToOne(where="entityType='AnotherType'")

你们有没有听说过这样的事情? 我可以理解ManyToOne可能不是正确的方法。

我正在使用标准的Hibernate 5,JPA和Spring Boot,所有这些都是通过Jackson Message Converter请求的。

由于

1 个答案:

答案 0 :(得分:1)

您可以使用一些filters,此过滤器可以使用某些特定条件或条件访问集合。

如果您提供有关您正在使用的技术的更多信息,我们可以提供更具体的答案。