Hi,
I have two classes:
* Subscriber, child of User
* Profile, related to Subscriber, one per subscriber
I want to automatically save Profile, when I persist Subscriber. What happens is that Subscriber gets persisted. Hibernate tries to
update Profile in stead of
insert it, resulting in an error.
Any ideas?
I have mapped the relation like so:
User.hbm.xml
[codeb]
<class
name="User"
table="Users"
discriminator-value="U"
>
<id
name="userID"
column="UserID"
type="long"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>
<discriminator
column="Subclass"
type="char"
/>
<subclass
name="Subscriber"
discriminator-value="S"
>
[/code]
<one-to-one
name="profile"
class="Profile"
cascade="all"
outer-join="auto"
constrained="false"
property-ref="subscriber"
/>
Profile.hbm.xml
Code:
<class
name="Profile"
table="Profiles"
proxy="Profile"
>
<id
name="subscriberID"
column="SubscriberID"
type="long"
unsaved-value="null"
>
<generator class="foreign">
<param name="property">subscriber</param>
</generator>
</id>
<many-to-one
name="subscriber"
class="Subscriber"
cascade="none"
outer-join="auto"
constrained="false"
unique="true"
not-null="false"
column="SubscriberID"
/>
Kind regards,
Marc