I am getting the error:
Caused by: org.hibernate.AnnotationException: Referenced column 'sub_categoryvid' mapped by target property 'id' occurs out of order in the list of '@JoinColumn's
at org.hibernate.boot.model.internal.BinderHelper.findPropertiesByColumns(BinderHelper.java:544) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
I have a table with compose id that has reference to itself:
Table diagram
represented like this:
public class SubCategoryItemPK implements Serializable {
@Column(name = "ItemID", insertable = false, updatable = false, unique = true, nullable = false)
private Integer itemId;
@Column(name = "SubCategoryVID", insertable = false, updatable = false, unique = true, nullable = false)
private Integer subCategoryVId;
....
}
public class SubCategoryItem implements Serializable {
@EmbeddedId private SubCategoryItemPK id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumnsOrFormulas(
value = {
@JoinColumnOrFormula(
column =
@JoinColumn(
referencedColumnName = "ItemID",
name = "ParentItemID")),
@JoinColumnOrFormula(
formula =
@JoinFormula(
referencedColumnName = "SubCategoryVID",
value = "SubCategoryVID"))
})
private SubCategoryItem parentSubCategoryItem;
...
BinderHelper.java has this comment:
enter image description here
When I debug I see that I got the error when is processing the second column (sub_categoryvid) and because is not the same than the first property (itemid):
enter image description here
Do you know how to fix this or a workaround??
This happend just when I start the application.
Sandra Milena Gomez Rios is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.