I have the following usage in JoinColumns
@Entity
public class EntityOne{
private String action;
private String type;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumns({
@JoinColumn(name = "action", referencedColumnName = "action_name", updatable = false, insertable = false),
@JoinColumn(name = "type", referencedColumnName = "type_name", updatable = false, insertable = false)
})
private Entitytwo entitytwo;
}
And
@Entity
public class EntityTwo {
@Id
@Column(name = "type_name")
private String typeName;
@Id
@Column(name = "action_name")
private String actionName;
}
This setup causes hibernate error of
Referenced column '" + column.getName()
+ "' mapped by target property '" + property.getName()
+ "' occurs out of order in the list of '@JoinColumn's
If i change the order inside the @JoinColumns it seems to work, but can stop working at the next time the application starts.
The hibernate comments at the begining of the relevant code states:
// Now we need to line up the properties with the columns in the
// same order they were specified by the @JoinColumn annotations
// this is very tricky because a single property might span
// multiple columns.
// TODO: For now we only consider the first property that matched
// each column, but this means we will reject some mappings
// that could be made to work for a different choice of
// properties (it's also not very deterministic)
And on the relevant code itself:
// we have the first column of a new property
orderedProperties.add( property );
if ( property.getColumnSpan() > 1 ) {
if ( !property.getColumns().get(0).equals( column ) ) {
// the columns have to occur in the right order in the property
throw new AnnotationException("Referenced column '" + column.getName()
+ "' mapped by target property '" + property.getName()
+ "' occurs out of order in the list of '@JoinColumn's");
}
currentProperty = property;
lastPropertyColumnIndex = 1;
}
How should i set the @JoinColumn for it to consistently work?