Description:
|
I get a MappingException for @ManyToOne join if table on the left of the association is alphabetically lower than table on the right
I have tables VO_USER, V_ORGANIZATIONAL and VO_AREA
VO_USER has USR_IDR as primary key.
V_ORGANIZATIONAL has a composite primary key of BUSINESS_AREA_CODE and CODE
VO_AREA has BUS_ARA_IDR as the primary key
I get the following exception when I join the VO_USER table with the V_ORGANIZATIONAL table
"org.hibernate.MappingException: Unable to find column with logical name: BUSINESS_AREA_CODE in org.hibernate.mapping.Table(V_ORGANIZATIONAL_GRADE) and its related supertables and secondary tables"
Howerver, if I rename the table V_ORGANIZATIONAL to VO_ORGANIZATIONAL, it works fine - which makes me conclude that it is an issue with the alphabetical ordering of the tables in the association. The table name on the left side of the @ManyToOne join must be alphabetically greater than the table on the right side - perhaps of the way hibernate loads the classes ??
Can someone confirm that is the issue, and what is the workaround/solution as I dont want to change the name of the table
The simplified Code :
{code}
@Entity
@org.hibernate.annotations.Entity(mutable = true)
@Table(name = "VO_USER")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "user")
public class User implements Serializable
{
private static final long serialVersionUID = -1894472442328538017L;
@Id
@Column(name = "USR_IDR")
private String userId;
@ManyToOne
@JoinColumn(name = "BUS_ARA_IDR", insertable = false, updatable = false, unique = false, nullable = false)
private BusinessArea businessArea;
@ManyToOne(targetEntity = Organizational.class)
@JoinColumns( {
@JoinColumn(name = "BUS_ARA_IDR", referencedColumnName = "BUSINESS_AREA_CODE", unique = false, insertable = false, updatable = false, nullable=true),
@JoinColumn(name = "USR_GRD", referencedColumnName = "CODE", unique = false, insertable = false, updatable = false, nullable=true)
})
private Organizational organizational;
....
}
{code}
{code}
@Entity
@Table(name = "V_ORGANIZATIONAL")
@IdClass(OrganizationalKey.class)
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "organization")
public class Organizational implements CodedValue,
Comparable<Organizational>, Serializable
{
private static final long serialVersionUID = 7414956278287853961L;
@Id
private String code;
@Id
private BusinessArea businessArea;
private Organizational()
{
}
....
}
{code}
{code}
public class OrganizationalKey implements Serializable
{
private static final long serialVersionUID = -8022957102173252455L;
@ManyToOne(targetEntity = BusinessArea.class)
@JoinColumn(name = "BUSINESS_AREA_CODE", insertable = false, updatable = false)
private BusinessArea businessArea;
@Column(name = "CODE", length = 5, insertable = false, updatable = false)
private String code;
OrganizationalKey()
{
}
....
}
{code}
{code}
@Entity
@Table(name = "VO_AREA")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "organization")
public class BusinessArea implements CodedValue, Serializable
{
private static final long serialVersionUID = 6911068689852530787L;
@Id
@Column(name = "BUS_ARA_IDR", length = 3, updatable = false)
private String code;
private BusinessArea()
{
};
}
{code}
|