I have an entity A with two @OneToMany association with the entity B, the difference is an attribute of the entity B that change in 1 and 2 association.
@Entity
@Table
class AEntity {
@Id
Long id;
@OneToMany(mappedBy = "a", cascade = CascadeType.PERSIST, orphanRemoval = true)
private List<BEntity> bFirstList;
@OneToMany(mappedBy = "a", cascade = CascadeType.PERSIST, orphanRemoval = true)
private List<BEntity> bSecondList;
}
@Entity
@Table
class BEntity {
@Id
Long id;
@ManyToOne
@JoinColumn(name = "a_id")
private AEntity a;
private BType type;
}
enum BType {
FIRST,
SECOND;
}
I want in List bFirstList; all instance where type is FIRST, and in bSecondList all instances where type is SECOND.
How can I acheive this? Is it possible to specify a custom query for the join or is there a better approach to the problem?