I have two objects:
InstrumentStatic and InstrumentDynamic that are associated in one-to-one relationship
How can I insert two new isntances associated one-to-one in one transaction?
Becase when I do somethig like this:
Code:
InstrumentStatic instrumentStatic = new InstrumentStatic();
InstrumentDynamic instrumentDynamic = new InstrumentDynamic();
instrumentStatic.setInstrumentDynamic(instrumentDynamic);
session.saveOrUpdate(instrumentStatic);
I obtain error:
ExceptionDAO: ids for this class must be manually assigned before calling save(): com.domainmodel.InstrumentDynamic wraps: [net.sf.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.domainmodel.InstrumentDynamic]
Mapping:
InstrumentStatic (parent)
Code:
public class InstrumentStatic implements java.io.Serializable {
public Long instrumentId;
public String name;
private InstrumentDynamic instrumentDynamic;
// ... etc...
public void setInstrumentDynamic(InstrumentDynamic instrumentDynamic) {
this.instrumentDynamic = instrumentDynamic;
}
/**
* @hibernate.one-to-one class="com.domainmodel.InstrumentDynamic" cascade="all"
*/
public InstrumentDynamic getInstrumentDynamic() {
return instrumentDynamic;
}
public void setInstrumentId(Long instrumentId) {
this.instrumentId = instrumentId;
}
/**
* @hibernate.id generator-class="native"
*/
public Long getInstrumentId() {
return instrumentId;
}
// ......... etc............
InstrumentDynamic (child)
Code:
public class InstrumentDynamic implements java.io.Serializable {
public Long instrumentId;
public InstrumentStatic instrument;
public Long totalTrades;
public void setInstrumentId(Long instrumentId) {
this.instrumentId = instrumentId;
}
/**
* @hibernate.id generator-class="assigned"
*/
public Long getInstrumentId() {
return instrumentId;
}
public void setInstrument(InstrumentStatic instrument) {
this.instrument = instrument;
}
/**
* @hibernate.one-to-one column="instrumentId" class="com.domainmodel.InstrumentStatic" cascade="all" constrained="true"
* @ hibernate.one-to-one class="com.domainmodel.InstrumentDynamic" cascade="all"
*/
public InstrumentStatic getInstrument() {
return instrument;
}
// ........ etc.................