-->
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.  [ 2 posts ] 
Author Message
 Post subject: Saving new objects problem (Sets again)
PostPosted: Thu May 06, 2004 4:42 am 
Newbie

Joined: Wed Mar 24, 2004 6:18 am
Posts: 15
Hi! I have a table "tableA" with a one-to-many association to "tableB", so the "tableA" Java object has a java.util.Set of "tableB" objects.

If I create a new "tableA" object with some "tableB" objects added to it, when I want to save the "tableA" object, it has a null ID as expected (unsaved-value="null"). The problem is that the tablaA.id property of the "tableB" objects is also null, and I get a JDBC error because of that.

If I save a "tableA" object with no "tableB" objects on it, and later I add some "tableB's", then it works OK because now "tableA.id" is not null.

The property mapping files look like this:

table1:
Code:
   
<set
        name="table2"
        lazy="true"
        inverse="true"
        cascade="all-delete-orphan"
        sort="unsorted"
    >
        <key>
            <column name="id" />
        </key>
        <one-to-many
            class="my.package.table2"
        />
    </set>


table2:
Code:
<many-to-one
        name="table1"
        class="my.package.table1"
        not-null="true"
    >
        <column name="id" />
    </many-to-one>


Is it possible to save a newly created "tableA" object with "tableB" childs at the same time?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 6:21 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What you expect works properly on Hibernate.
Did you set table2.setTable1(table1) as described in the Parent/Child relationship chapter ?

_________________
Emmanuel


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

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.