Hi,
I don't know how to map the following (legacy) situation:
Tables:
SUBSYSTEM(
SS_CODE,
VERSION)
EQUIPMENT(
EQ_CODE,
VERSION, SS_CODE)
there is a FK from EQUIPMENT(SS_CODE,VERSION) to SUBSYSTEM(SS_CODE, VERSION)
so in Equipment, the "version" column is used in the PK and in the relation.
Here is my initial mapping:
Code:
public class Subsystem {
@EmbeddedId
private SubsystemId compositeId;
@Embeddable
public static class SubsystemId implements Serializable {
@Column(name="SS_CODE")
private String code;
@Column(name="VERSION")
private Integer version;
}
}
public class Equipment {
@EmbeddedId
private EquipmentId compositeId;
@ManyToOne
@JoinColumns({
@JoinColumn(name="SS_CODE", referencedColumnName="SS_CODE"),
@JoinColumn(name="VERSION", referencedColumnName="VERSION")
})
private Subsystem subsystem;
@Embeddable
public static class EquipementId implements Serializable {
@Column(name="EQ_CODE")
private String code;
@Column(name="VERSION")
private Integer version;
}
}
I get the following exception:
Quote:
org.hibernate.MappingException: Repeated column in mapping for entity: Equipment column: VERSION (should be mapped with insert="false" update="false")
So I tried the given advice:
Code:
@ManyToOne
@JoinColumns({
@JoinColumn(name="SS_CODE", referencedColumnName="SS_CODE"),
@JoinColumn(name="VERSION", referencedColumnName="VERSION", insertable=false, updatable=false)
})
private Subsystem subsystem;
But now I get the following error:
Quote:
org.hibernate.AnnotationException: Mixing insertable and non insertable columns in a property is not allowed: Equipmentsubsystem
Do you have any suggestion on how to tell hibernate to reuse columns already mapped in the composite Id?
I'm using Hibernate 3.5.0-Beta-2.
Thanks
Julien