【问题标题】:Spring, Hibernate, JPA, ManyToOne with added where clause or Differentiator column without the inhertianceSpring、Hibernate、JPA、ManyToOne 添加了 where 子句或不带继承的区分列
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

    • 太棒了,这正是我想要的!我已经用所使用的技术更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 2011-06-16
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    相关资源
    最近更新 更多