休眠@OneToMany,其中discriminatorValue ='SOMETHING'

时间:2019-08-25 18:06:40

标签: jpa hibernate-onetomany

pdp_billable_field_state包含各个字段的配置。 配置的所有者可以是任何数量的实体 每个与@DiscriminatorValue

匹配的实体的配置都是相同的
@Getter
@Setter
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "entity_type")
@Table(name = "pdp_billable_field_state")
public abstract class EntityFieldStateJpa extends AuditableJPA {

      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private Long id;

      @ManyToOne
      @JoinColumn(name = "status_id")
      private StatusJpa status;

      @Column(name = "field", columnDefinition= "varchar(255)")
      private String field;
      private boolean disabled;
      private boolean hidden;

    }


@DiscriminatorValue("PURCHASE")
public class PurchaseEntityFieldStateJpa extends EntityFieldStateJpa {}



@Getter
@Setter
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "pdp_purchase")
public class PurchaseJpa {

   // omitted

   @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
   // i do not have a join_column since all records with entity_type PURCHASE map to all purchases, as these are configurations used by all purchases. Should i try and introduce @JoinTable maybe?
   @Where(clause = "entity_type='PURCHASE'")
   private List<PurchaseEntityFieldStateJpa> fieldStates;

}

0 个答案:

没有答案