-->
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: Problem using Interceptor.isTransient() with composite-id
PostPosted: Fri Apr 07, 2006 4:28 pm 
Newbie

Joined: Wed Apr 05, 2006 5:58 pm
Posts: 13
Hibernate version: 3.1

I have a class Foo, and I have another class Bar whose composite id is Foo.id and a type. The Foo class holds a Set of Bars. I've implemented an Interceptor so that hibernate will know when Bar isTransient. The documention suggests to me that if i create a Foo, and add some Bars to it, when I attempt to persist Foo, the Bar objects will be persisted because i've implemented isTransient correctly, it knows to use Foo.id when inserting the Bar objects into the db. However, that does not appear to be the case. The bar insert errors out because the id is null and of course part of the composite pkey on bar can't be null. Any thoughts? It seems like i could get past this if i had a reference to Foo in Bar, however that seems like a hack as I have no need for a bidirectional relationship between those classes.

Here are the relevant mapping docs.

<class name="FooParent" table="foo_parent">
...
<joined-subclass name="Foo" table="foo">
<key column="foo_id"/>
...
<set name="bars" cascade="save-update">
<key column="foo_id"/>
<one-to-many class="Bar"/>
</set>

</joined-subclass>
</class>

<class name="Bar" table="bar" discriminator-value="0">
<composite-id name="id" class="Bar$Identifier">
<key-property name="id" type="long" column="foo_id"/>
<key-property name="typeId" type="integer" column="type_id"/>
</composite-id>
<discriminator column="type_id" type="integer" insert="false"/>
<property name="col1"/>
<subclass name="Bar1" discriminator-value="1"/>
<subclass name="Bar2" discriminator-value="2"/>
</class>


Thanks


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.