Hi,
I have two tables in my database
KMS
-------
Instrument LONG (PrimaryKey)
------
RIMappings
----------------
Instrument LONG
FIELD_ID VARCHAR
--------------------
RIMappings consists of a compositeID of a foreignKey INSTRUMENT that references the KMS table and an assigned FIELD_ID.
An example of records in the database are as follows:
KMS:1
RIMappings:
1, BID
1, ASK
1, LAST
The issue that I have is that when I attempt to insert into the database, hibernate generates SQL Inserts that has a null value for the INSTRUMENT column in the RIMappings table.
In essence, what I am try to achieve over here is cascading the PrimaryKey of the KMS table (INSTRUMENT) to the compositeKey of the RIMappings table when I save the object.
My POJOS are defined as follows:
KMS.java
Code:
@Entity
@Table(schema="DBP", name="KMS")
public class KMS
{
private long instrument;
private Set<RIMappings> RIM=new HashSet<RIMappings>();
@Id
@GenericGenerator(name="seq_id",strategy="sequence",parameters={@Parameter(name="sequence",value="HIB_SEQ")}
@GeneratedValue(generator="seq_id")
public long getInstrument() {
return instrument;
}
public void setInstrument(long instrument) {
this.instrument = instrument;
}
@OneToMany(targetEntity=RIMappings.class,cascade=CascadeType.ALL)
@JoinColumn(name="INSTRUMENT")
public Set<RIMappings> getRIMappings()
{
return RIM;
}
public void setRIMappings(Set<RIMappings> RIM)
{
this.RIM=RIM;
}
}
RIMappings.javaCode:
@Entity
@Table(schema="DBP", name="RIMappings")
@IdClass(RIMappingsId.class)
public class RIMappings {
private Long instrument;
private String fieldId;
private KMS kms;
@Id
@Column(name="INSTRUMENT", insertable=false, updatable=false, nullable=false)
public Long getInstrument() {
return instrument;
}
public void setInstrument(Long instrument) {
this.instrument = instrument;
}
@Id
@Column(name="FIELD_ID", nullable=false)
public String getFieldId() {
return fieldId;
}
public void setFieldId(String fieldId) {
this.fieldId = fieldId;
}
@ManyToOne(targetEntity = KMS.class)
@JoinColumn(name = "INSTRUMENT", nullable = false, insertable=false, updatable=false)
public KMS getKMS() {
return kms;
}
public void setKMS(KMS kms) {
this.kms = kms;
}
}
RIMappingsId.classCode:
@Embeddable
public class RIMappingsId implements Serializable{
/**
*
*/
private static final long serialVersionUID = 7139311515487739123L;
private Long instrument;
private String fieldId;
@Column(name = "INSTRUMENT", nullable = false)
public Long getInstrument() {
return this.instrument;
}
public void setInstrument(Long instrument) {
this.instrument = instrument;
}
@Column(name = "FIELD_ID", nullable = false)
public String getFieldId() {
return this.fieldId;
}
}