-->
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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Parent child save order
PostPosted: Tue Mar 09, 2004 11:38 am 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
Hi,

Before this post I've read the parent child documentation and searched the form, but couldn't get the anwser to my problem.

The following link was usefull but it didn't solve my problem.
http://forum.hibernate.org/viewtopic.php?t=924744&highlight=automatically+save+children

I have a parent child relationship between TickTicket (parent) and TickOrderline (child). The relation between these objects is bi-directional.
In my code I create a parent object, a child object and then connect them together.

When hibernate tries to store the parent and the children into the database it first tries to insert the children (TickOrderline). This causes an exception due to the parent (TickTicket) does not exist.

It all runs in a transaction and when Hibernate calls the commit method an exception occurs.

Thanks,
Erwin.

Here are my files:

TickTicket.hbm.xml
Code:
<hibernate-mapping>

<class
    name="com.lcmg.ticket.persist.persistobject.TickTicket"
    table="tick_ticket"
>

    <id
        name="id"
        type="java.lang.String"
        column="id"
    >
<generator class="uuid.hex"/>
    </id>

    <property
        name="contentCode"
        type="java.lang.String"
        column="contentCode"
        not-null="true"
        length="255"
    />
    <property
        name="referenceId"
        type="java.lang.String"
        column="reference_id"
        not-null="true"
        length="32"
    />

    <!-- bi-directional one-to-many association to TickOrderline -->
    <set
        name="tickOrderlines"
        lazy="true"
        inverse="true"
        cascade="all"
    >
        <key>
            <column name="ticket_id" />
        </key>
        <one-to-many
            class="com.lcmg.ticket.persist.persistobject.TickOrderline"
        />
    </set>


</class>
</hibernate-mapping>



TickOrderline.hbm.xml:

Code:
<hibernate-mapping>

<class
    name="com.lcmg.ticket.persist.persistobject.TickOrderline"
    table="tick_orderline"
>

    <id
        name="id"
        type="java.lang.String"
        column="id"
    >
<generator class="uuid.hex"/>
    </id>

    <property
        name="numTimesValid"
        type="java.lang.Integer"
        column="num_times_valid"
        length="10"
    />
    <property
        name="numOfPersons"
        type="int"
        column="num_of_persons"
        not-null="true"
        length="10"
    />
    <property
        name="referenceId"
        type="java.lang.String"
        column="reference_id"
        not-null="true"
        length="32"
    />

    <!-- bi-directional many-to-one association to TickTicket -->
    <many-to-one
        name="tickTicket"
        class="com.lcmg.ticket.persist.persistobject.TickTicket"
        not-null="true"
        cascade="all"
    >
        <column name="ticket_id" />
    </many-to-one>

</class>
</hibernate-mapping>





Stacktrace:
Code:
2004-03-09 15:38:17,468 WARN  [main] [{testDoOrderMinimal}] net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 515, SQLState: 23000
2004-03-09 15:38:17,468 ERROR [main] [{testDoOrderMinimal}] net.sf.hibernate.util.JDBCExceptionReporter - [MTEST\MTESTDEVELOP1]Cannot insert the value NULL into column 'ticket_id', table 'MGRID_Ticketing.dbo.tick_orderline'; column does not allow nulls. INSERT fails.
2004-03-09 15:38:17,468 ERROR [main] [{testDoOrderMinimal}] net.sf.hibernate.util.JDBCExceptionReporter - could not insert: [com.lcmg.ticket.persist.persistobject.TickOrderline#8a9181b8fb300f3100fb300f3f880001]
java.sql.SQLException: [MTEST\MTESTDEVELOP1]Cannot insert the value NULL into column 'ticket_id', table 'MGRID_Ticketing.dbo.tick_orderline'; column does not allow nulls. INSERT fails.
   at com.inet.tds.a.a(Unknown Source)
   at com.inet.tds.b.new(Unknown Source)
   at com.inet.tds.b.executeUpdate(Unknown Source)
   at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at com.lcmg.ticket.domain.order.OrderTest.testCreateOrderSimple(OrderTest.java:218)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:395)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:279)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:171)
2004-03-09 15:38:17,468 ERROR [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Could not synchronize database state with session
net.sf.hibernate.JDBCException: could not insert: [com.lcmg.ticket.persist.persistobject.TickOrderline#8a9181b8fb300f3100fb300f3f880001]
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:478)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at com.lcmg.ticket.domain.order.OrderTest.testCreateOrderSimple(OrderTest.java:218)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:395)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:279)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:171)
Caused by: java.sql.SQLException: [MTEST\MTESTDEVELOP1]Cannot insert the value NULL into column 'ticket_id', table 'MGRID_Ticketing.dbo.tick_orderline'; column does not allow nulls. INSERT fails.
   at com.inet.tds.a.a(Unknown Source)
   at com.inet.tds.b.new(Unknown Source)
   at com.inet.tds.b.executeUpdate(Unknown Source)
   at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
   ... 22 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 09, 2004 12:13 pm 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
You need to bind each child with its parent.
Try the following approach:
Code:
public class Parent
{
    public void setChildren(Set children)
    {
         this.childred.clear();
         if (null == children)
             return;

         for (Iterator i = children.iterator(); i.hasNext();)
         {
              Child tmpChild = (Child) i.next();
              // binding each child with its parent
              tmpChild.setParent(this);
              // adding binded child to the collection
              this.children.add(tmpChild);
         }
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 09, 2004 1:28 pm 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
The child is bound to the parent.

Erwin.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 3:47 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Erwin,

then I don't know what is not correct. The similar mapping works for me only without lazy="true" in the Parent mapping.

And I see some strange property type mappings:
Code:
type="java.lang.String" type="java.lang.Integer" type="int"
don't know if it is correct.
Look into 5.2.2. Basic value types
http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s2-2

Leonid


Top
 Profile  
 
 Post subject: Re: Parent child save order
PostPosted: Wed Mar 10, 2004 3:53 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
erbruijn wrote:
Stacktrace:
[code]
2004-03-09 15:38:17,468 WARN [main] [{testDoOrderMinimal}] net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 515, SQLState: 23000
2004-03-09 15:38:17,468 ERROR [main] [{testDoOrderMinimal}] net.sf.hibernate.util.JDBCExceptionReporter - [MTEST\MTESTDEVELOP1]Cannot insert the value NULL into column 'ticket_id', table 'MGRID_Ticketing.dbo.tick_orderline'; column does not allow nulls. INSERT fails.


At the first line of stacktrace I see some WARN, if you send earlier messages and java code where you are saving/updating your Parent/Child association it could help.

Leonid


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 5:33 am 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
The log message contains a message which says that one of my objects is dirty?! Maybe this is the cause of the error? My app runs in a transaction and each time the database is accessed a new session is created!?

Erwin.

Code:
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.persister.AbstractEntityPersister - com.lcmg.ticket.persist.persistobject.TickOrderline.tickOrder is dirty
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.persister.AbstractEntityPersister - com.lcmg.ticket.persist.persistobject.TickOrderline.tickTicket is dirty
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Updating entity: [com.lcmg.ticket.persist.persistobject.TickOrderline#8a9181b8fb33bca900fb33bcb97a0001]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickOrderline.tickOrderlineStatusHistories#8a9181b8fb33bca900fb33bcb97a0001], was: [<unreferenced>]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickOrder.tickOrderlines#8a9181b8fb33bca900fb33bcb97a0003], was: [<unreferenced>]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickOrder.tickOrderProperties#8a9181b8fb33bca900fb33bcb97a0003], was: [<unreferenced>]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickOrder.tickOrderStatusHistories#8a9181b8fb33bca900fb33bcb97a0003], was: [<unreferenced>]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickOrderCategory.tickOrderProperties#8a9181b8fb33bca900fb33bcb98a0005], was: [<unreferenced>]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickTicketcodeHandler.tickCaseTicketcodes#DEFAULT_TICKETCODE_HANDLER_ID], was: [com.lcmg.ticket.persist.persistobject.TickTicketcodeHandler.tickCaseTicketcodes#DEFAULT_TICKETCODE_HANDLER_ID]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickCaseTicketcodes#DELIVERY_CHANNEL_SMS_NPM_ID], was: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickCaseTicketcodes#DELIVERY_CHANNEL_SMS_NPM_ID]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickDeviceManufacturers#DELIVERY_CHANNEL_SMS_NPM_ID], was: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickDeviceManufacturers#DELIVERY_CHANNEL_SMS_NPM_ID]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickCaseBarcodes#DELIVERY_CHANNEL_SMS_NPM_ID], was: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickCaseBarcodes#DELIVERY_CHANNEL_SMS_NPM_ID]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickTickets#DELIVERY_CHANNEL_SMS_NPM_ID], was: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickTickets#DELIVERY_CHANNEL_SMS_NPM_ID]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickDeliveryDevices#DELIVERY_CHANNEL_SMS_NPM_ID], was: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickDeliveryDevices#DELIVERY_CHANNEL_SMS_NPM_ID]
2004-03-10 08:46:38,281 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - Collection found: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickCaseDeliveries#DELIVERY_CHANNEL_SMS_NPM_ID], was: [com.lcmg.ticket.persist.persistobject.TickDeliveryChannel.tickCaseDeliveries#DELIVERY_CHANNEL_SMS_NPM_ID]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 4:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the real code you use with the mapping you showed

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 5:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
oh, this is certainly a broken equals()/hashCode() implementation
Read the wiki page on that subject

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 5:54 am 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
Sorry I provided you the wrong information. We are just using one session for all the work! I can't send you the code because of it is distributed over a lot of classes... But I can send you the persist objects:


Code:
public class TickOrderline {
    /** identifier field */
    private String id;

    /** nullable persistent field */
    private Integer numTimesValid;

    /** persistent field */
    private int numOfPersons;

    /** persistent field */
    private String referenceId;

    /** persistent field */
    private com.lcmg.ticket.persist.persistobject.TickOrder tickOrder;

    /** persistent field */
    private com.lcmg.ticket.persist.persistobject.TickTicket tickTicket;

    /** persistent field */
    private com.lcmg.ticket.persist.persistobject.TickOrderlineType tickOrderlineType;

    /** persistent field */
    private Set tickOrderlineStatusHistories = new HashSet();

    /** full constructor */
    public TickOrderline(Integer numTimesValid, int numOfPersons, String referenceId, com.lcmg.ticket.persist.persistobject.TickOrder tickOrder,
        com.lcmg.ticket.persist.persistobject.TickTicket tickTicket, com.lcmg.ticket.persist.persistobject.TickOrderlineType tickOrderlineType,
        Set tickOrderlineStatusHistories) {
        this.numTimesValid = numTimesValid;
        this.numOfPersons = numOfPersons;
        this.referenceId = referenceId;
        this.tickOrder = tickOrder;
        this.tickTicket = tickTicket;
        this.tickOrderlineType = tickOrderlineType;
        this.tickOrderlineStatusHistories = tickOrderlineStatusHistories;
    }

    /** default constructor */
    public TickOrderline() {
    }

    /** minimal constructor */
    public TickOrderline(int numOfPersons, String referenceId, com.lcmg.ticket.persist.persistobject.TickOrder tickOrder,
        com.lcmg.ticket.persist.persistobject.TickTicket tickTicket, com.lcmg.ticket.persist.persistobject.TickOrderlineType tickOrderlineType,
        Set tickOrderlineStatusHistories) {
        this.numOfPersons = numOfPersons;
        this.referenceId = referenceId;
        this.tickOrder = tickOrder;
        this.tickTicket = tickTicket;
        this.tickOrderlineType = tickOrderlineType;
        this.tickOrderlineStatusHistories = tickOrderlineStatusHistories;
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getNumTimesValid() {
        return this.numTimesValid;
    }

    public void setNumTimesValid(Integer numTimesValid) {
        this.numTimesValid = numTimesValid;
    }

    public int getNumOfPersons() {
        return this.numOfPersons;
    }

    public void setNumOfPersons(int numOfPersons) {
        this.numOfPersons = numOfPersons;
    }

    public String getReferenceId() {
        return this.referenceId;
    }

    public void setReferenceId(String referenceId) {
        this.referenceId = referenceId;
    }

    public com.lcmg.ticket.persist.persistobject.TickOrder getTickOrder() {
        return this.tickOrder;
    }

    public void setTickOrder(com.lcmg.ticket.persist.persistobject.TickOrder tickOrder) {
        this.tickOrder = tickOrder;
    }

    public com.lcmg.ticket.persist.persistobject.TickTicket getTickTicket() {
        return this.tickTicket;
    }

    public void setTickTicket(com.lcmg.ticket.persist.persistobject.TickTicket tickTicket) {
        this.tickTicket = tickTicket;
    }

    public com.lcmg.ticket.persist.persistobject.TickOrderlineType getTickOrderlineType() {
        return this.tickOrderlineType;
    }

    public void setTickOrderlineType(com.lcmg.ticket.persist.persistobject.TickOrderlineType tickOrderlineType) {
        this.tickOrderlineType = tickOrderlineType;
    }

    public Set getTickOrderlineStatusHistories() {
        return this.tickOrderlineStatusHistories;
    }

    public void setTickOrderlineStatusHistories(Set tickOrderlineStatusHistories) {
        this.tickOrderlineStatusHistories = tickOrderlineStatusHistories;
    }

    /**
     * This method adds the submitted Child object to this class and
     * assigns the Parent member of the Child Object to this object.
    */
    public void addTickOrderlineStatusHistory(TickOrderlineStatusHistory child) {
        if (this.tickOrderlineStatusHistories == null) {
            this.setTickOrderlineStatusHistories(new HashSet());
        }

        this.tickOrderlineStatusHistories.add(child);
        child.setTickOrderline(this);
    }

    public String toString() {
        return new ToStringBuilder(this).append("id", getId()).toString();
    }

    public boolean equals(Object other) {
        if (!(other instanceof TickOrderline)) {
            return false;
        }

        TickOrderline castOther = (TickOrderline) other;

        return new EqualsBuilder().append(this.getId(), castOther.getId()).isEquals();
    }

    public int hashCode() {
        return new HashCodeBuilder().append(getId()).toHashCode();
    }
}





Code:
public class TickTicket {
    /** identifier field */
    private String id;

    /** persistent field */
    private String contentCode;

    /** persistent field */
    private String referenceId;

    /** persistent field */
    private com.lcmg.ticket.persist.persistobject.TickDeliveryFormat tickDeliveryFormat;

    /** persistent field */
    private com.lcmg.ticket.persist.persistobject.TickDeliveryChannel tickDeliveryChannel;

    /** persistent field */
    private Set tickOrderlines = new HashSet();

    /** persistent field */
    private Set tickTicketStatusHistories = new HashSet();

    /** persistent field */
    private Set tickTicketProperties = new HashSet();

    /** full constructor */
    public TickTicket(String contentCode, String referenceId, com.lcmg.ticket.persist.persistobject.TickDeliveryFormat tickDeliveryFormat,
        com.lcmg.ticket.persist.persistobject.TickDeliveryChannel tickDeliveryChannel, Set tickOrderlines, Set tickTicketStatusHistories,
        Set tickTicketProperties) {
        this.contentCode = contentCode;
        this.referenceId = referenceId;
        this.tickDeliveryFormat = tickDeliveryFormat;
        this.tickDeliveryChannel = tickDeliveryChannel;
        this.tickOrderlines = tickOrderlines;
        this.tickTicketStatusHistories = tickTicketStatusHistories;
        this.tickTicketProperties = tickTicketProperties;
    }

    /** default constructor */
    public TickTicket() {
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getContentCode() {
        return this.contentCode;
    }

    public void setContentCode(String contentCode) {
        this.contentCode = contentCode;
    }

    public String getReferenceId() {
        return this.referenceId;
    }

    public void setReferenceId(String referenceId) {
        this.referenceId = referenceId;
    }

    public com.lcmg.ticket.persist.persistobject.TickDeliveryFormat getTickDeliveryFormat() {
        return this.tickDeliveryFormat;
    }

    public void setTickDeliveryFormat(com.lcmg.ticket.persist.persistobject.TickDeliveryFormat tickDeliveryFormat) {
        this.tickDeliveryFormat = tickDeliveryFormat;
    }

    public com.lcmg.ticket.persist.persistobject.TickDeliveryChannel getTickDeliveryChannel() {
        return this.tickDeliveryChannel;
    }

    public void setTickDeliveryChannel(com.lcmg.ticket.persist.persistobject.TickDeliveryChannel tickDeliveryChannel) {
        this.tickDeliveryChannel = tickDeliveryChannel;
    }

    public Set getTickOrderlines() {
        return this.tickOrderlines;
    }

    public void setTickOrderlines(Set tickOrderlines) {
        this.tickOrderlines = tickOrderlines;
    }

    /**
     * This method adds the submitted Child object to this class and
     * assigns the Parent member of the Child Object to this object.
    */
    public void addTickOrderline(TickOrderline child) {
        if (this.tickOrderlines == null) {
            this.setTickOrderlines(new HashSet());
        }

        this.tickOrderlines.add(child);
        child.setTickTicket(this);
    }

    public Set getTickTicketStatusHistories() {
        return this.tickTicketStatusHistories;
    }

    public void setTickTicketStatusHistories(Set tickTicketStatusHistories) {
        this.tickTicketStatusHistories = tickTicketStatusHistories;
    }

    /**
     * This method adds the submitted Child object to this class and
     * assigns the Parent member of the Child Object to this object.
    */
    public void addTickTicketStatusHistory(TickTicketStatusHistory child) {
        if (this.tickTicketStatusHistories == null) {
            this.setTickTicketStatusHistories(new HashSet());
        }

        this.tickTicketStatusHistories.add(child);
        child.setTickTicket(this);
    }

    public Set getTickTicketProperties() {
        return this.tickTicketProperties;
    }

    public void setTickTicketProperties(Set tickTicketProperties) {
        this.tickTicketProperties = tickTicketProperties;
    }

    /**
     * This method adds the submitted Child object to this class and
     * assigns the Parent member of the Child Object to this object.
    */
    public void addTickTicketProperty(TickTicketProperty child) {
        if (this.tickTicketProperties == null) {
            this.setTickTicketProperties(new HashSet());
        }

        this.tickTicketProperties.add(child);
        child.setTickTicket(this);
    }

    public String toString() {
        return new ToStringBuilder(this).append("id", getId()).toString();
    }

    public boolean equals(Object other) {
        if (!(other instanceof TickTicket)) {
            return false;
        }

        TickTicket castOther = (TickTicket) other;

        return new EqualsBuilder().append(this.getId(), castOther.getId()).isEquals();
    }

    public int hashCode() {
        return new HashCodeBuilder().append(getId()).toHashCode();
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 6:23 am 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
Browsing my log I can see that an ID is generated for the Ticket object. The Ticket object is stored using the saveOrUpdate (implictly done by Hibernate), so the Ticket object exists in the Session. But when I explicit call the saveOrUpdate I get an error that the ticket_id cannot be null, see my first question in this thread!

I don't get it anymore, what is wrong with my app?

Erwin.

Log:
Code:
2004-03-11 11:01:08,234 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - [b]saveOrUpdate() unsaved instance[/b]
2004-03-11 11:01:08,234 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - [b]generated identifier: 8a9181b8fb395e2a00fb395e3b8a0006[/b]
2004-03-11 11:01:08,234 DEBUG [main] [{testDoOrderMinimal}] net.sf.hibernate.impl.SessionImpl - [b]saving [com.lcmg.ticket.persist.persistobject.TickTicket#8a9181b8fb395e2a00fb395e3b8a0006][/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 7:16 am 
Newbie

Joined: Wed Mar 10, 2004 11:46 pm
Posts: 7
Location: china
try this.
Code:
Parent p = new parent();
session.save(parent);
parent.setChildren (new HashSet());
parent.getChildren.add(child);
session.saveOrUpdate(parent);
session.flush();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 7:33 am 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
I just want to perform a save (saveOrUpdate) once! First all persist object are created in memory, and when this is done I call the saveOrUpdate!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 10:08 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
erbruijn wrote:
I just want to perform a save (saveOrUpdate) once! First all persist object are created in memory, and when this is done I call the saveOrUpdate!


I don't know what is wrong 'cause I did not see the whole code, so I can only suggest you :)

1. try to replace all type="java.lang.String" to type="string"; all type="java.lang.Integer" and type="int to type="integer";

2. then restart your application and look carefully at your debug log for some kind of hibernate mapping erros;

3. in the Parent class try to comment association with the Child and try to save Parent class. That is in the TickTicket mapping comment one-to-many association with TickOrderline
Code:
<set
        name="tickOrderlines"
        lazy="true"
        inverse="true"
        cascade="all"
    >
        <key>
            <column name="ticket_id" />
        </key>
        <one-to-many
            class="com.lcmg.ticket.persist.persistobject.TickOrderline"
        />
    </set>

try to save your TickTicket. Is it saved?

4. The same Parent/Child mapping works for me, only without type="java.lang.String", .., lazy="true" and without cascade="all" in the Child-to-Parent association. Try to remove cascade="all" in the Child-to-Parent many-to-one association.

Experiment :)
Leonid


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 12:37 pm 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
Hi shl,

Thanks for your reaction, but:

1. the types 'java.lang.String', 'java.lang.Integer', etc must work, see: http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s2

3a. What do you mean with 'in the Parent class try to comment association with the Child and try to save Parent class'

3b. I don't want to save my parent manually. This is what hibernate do for me!

Erwin.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 2:02 pm 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
[quote="erbruijn"]
3a. What do you mean with 'in the Parent class try to comment association with the Child and try to save Parent class'[/qoute]
I meant, try to save Parent class (TickTicket in your case) without any relation with his children (TickOrderline), and look if it is saved ok.

[quote="erbruijn"]
3b. I don't want to save my parent manually. This is what hibernate do for me![/qoute]
I am not sure if it is possible. one-to-one mapping has constrained="true" attribute that could help you, but many-to-one mapping that you use in your Child has not this magic attribute. If your look into "9.3. Cascades"
Code:
Parent p = (Parent) session.load(Parent.class, pid);
Child c = new Child();
p.addChild(c);
session.flush();

you will see that parent is already saved. As rule I save parent and it saves all his children with cascade="all" I think it is more correct behavior.

And check if your TickTicket.hbm.xml registered in hibernate.cfg.xml or where it should be registered in your application.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.