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
|