-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: one-to-one - how to insert couple in one transaction?
PostPosted: Wed Mar 24, 2004 2:19 pm 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
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.................




Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.