'Spring JPA - referencedColumnNames [...] not mapped to a single property - Issue with @IdClass
I am facing the issue reported as subject when dealing with the following example:
[other irrelevant annotations]
@IdClass(KeyDAO.class)
public class KeyDAO implements Serializable {
@Id
@NotNull
private String KEYGROUP;
@Id
@NotNull
private String KEYVAL;
[...]
@OneToMany(mappedBy = "KEY")
@ToString.Exclude
private List<OrderDateDAO> ODATES;
}
[other irrelevant annotations]
@IdClass(OrderDateDAO.class)
public class OrderDateDAO implements Serializable {
[...]
@Id
@NotNull
private String ODTTYPE;
[...]
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(formula = @JoinFormula(value = Constants.DART_KEYGROUP_ODTTYPE, referencedColumnName = "KEYGROUP")),
@JoinColumnOrFormula(column = @JoinColumn(name = "ODTTYPE", referencedColumnName = "KEYVAL", insertable = false, updatable = false))
})
@ToString.Exclude
@OrderBy("ORDERASC ASC")
private KeyDAO KEY;
}
Basically, OrderDateDAO shall be joined with KeyDAO, and both use an @IdClass annotation. By following the tips on this site, I decided to use a JoinColumnsOrFormulas annotation, because:
- the real column to join is ODTTYPE <-> KEYVAL
- the KEY table shall be narrowed down by setting a specific fixed value for the KEYGROUP column
Currently, I am getting the following exception:
Caused by: org.hibernate.AnnotationException: referencedColumnNames(KEYGROUP, KEYVAL) of eu.unicredit.dtm.dtm_be.dao.oracle.OrderDateDAO.id.KEY referencing eu.unicredit.dtm.dtm_be.dao.oracle.KeyDAO not mapped to a single property
I have tried several other options, but still the error occurs.
Any help or suggestions here?
Thank you.
Regards, A.M.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
