JPA one-to-many filtering

前端 未结 4 1904
遇见更好的自我
遇见更好的自我 2021-02-05 05:20

We are nesting several entities. However upon retrieving we only want to get those entities which are active.

@Entity
public class System {
  @Id
  @Column(name          


        
4条回答
  •  [愿得一人]
    2021-02-05 05:54

    Another hibernate way of doing it with @Where:

    @Entity
    public class System {
      @Id
      @Column(name = "ID")
      private Integer id;
    
      @OneToMany(mappedBy = "system")
      @Where(clause = "active = true")
      private Set systempropertys;
    }
    
    @Entity
    public class Systemproperty {
      @Id
      @Column(name = "ID")
      private Integer id;
    
      @Id
      @Column(name = "ACTIVE")
      private Integer active;
    }
    

提交回复
热议问题