-->
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-toone with a custom ID generator and a cascade="all
PostPosted: Thu May 20, 2004 7:31 pm 
Newbie

Joined: Thu May 20, 2004 6:34 pm
Posts: 8
I'm having difficulty with a one-to-one mapping.


Class A (most all of my classes actually) uses a custom id generator that is contained in my application:
<id name="tid" type="long">
<generator class="topaz.dataAdapter.Sequencer"/>
</id>

Class A contains a one-to-one mapping to class B:
<one-to-one name="data"
class="TLImageData"
outer-join="false"
cascade="all"/>

Since Class A and Class B share the same primary key, Class be uses a foreign generator for its id:
<generator class="foreign">
<param name="property">tlimage</param>
</generator>

Class B also contains a one-to-one mapping to class A:
<one-to-one name="tlimage"
class="TLImage"
constrained="true" />

My problem is that I cannot save due to an apparent circularity:
1. When Class A is saved I get an error "object references an unsaved transient instance - save the transient instance before flushing".
2. However if I reverse the cascade so that Class B (instead of Class A) has a 'cascade="all" attibute in it's one-to-one, then I get a hibernate error stating that I am attempting to save a null value.
I believe that what's happening is that
(a) Class A cannot be saved before Class B because hibernate is insisting that Class B should be saved first, but
(b) Class B cannot be saved before Class A because its foreign id generator requires that Class A's id already exist - which doesn't happen until Class A is saved.
It's not really clear to me why Hibernate insists that Hibernate is not willing to save Class A before Class B.

Can someone enlighten me?

Thanks,

Frank

_________________
Frank Kurzawa


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.