I defined a many-to-many relation between two entities with a composite key. The problem is that when I get the join object it is filtered with only one side of the relation and not both side.
The picture makes the problem clearer. Here what im looking for is dtid=185 and prid=352 but what I get from many-to-many relation is two highlighted rows.
Entiry D:
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "d", orphanRemoval = true)
private List<DP> dp = new ArrayList<DP>();
Entity P:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "p")
private List<DP> dp = new ArrayList<DP>();
PK class:
public class DPPK implements Serializable{
private Integer d;
private Integer p;
}
Join:
@IdClass(DPPK.class)
@Entity
@Table(name = "definition_property")
@NamedQueries({
@NamedQuery(name = "DP.findAll", query = "SELECT d FROM DP d")})
public class DefinitionProperty extends AbstractEntity{
@Id
@JoinColumn(name = "dtid", referencedColumnName = "id")
@ManyToOne(optional = false)
private D d;
@Id
@JoinColumn(name = "prid", referencedColumnName = "id")
@ManyToOne(optional = false)
private P p;
@Column(name = "initial_value")
@Basic(optional = false)
private String initialValue;