Hi,
I have two tables:
Subscriber and Profile
Each subscriber has max one profile.
I have mapeed the profile as a foreign key association. However, when I create a new subscriber with an emtpy profile, the profile doesn't get saved.
Subscriber.java
/** * @hibernate.one-to-one outer-join="false" unsaved-value="null" * class="nl.msw.dates4free.business.entities.profile.Profile" cascade="all" * @return Returns the profile. */ public Profile getProfile() { return profile; }
Profile.java
/** * @hibernate.id generator-class="foreign" column="SubscriberID" type="long" unsaved-value="null" * @hibernate.generator-param name="property" value="subscriber" * @return Returns the subscriberID. */ public long getSubscriberID() { return subscriberID; } /** * @param subscriberID The subscriberID to set. */ public void setSubscriberID(long subscriberID) { this.subscriberID = subscriberID; } /** * @hibernate.many-to-one class="nl.msw.dates4free.business.entities.Subscriber" unique="true" constrained="true" cascade="all" * @return Returns the subscriber. */ public Subscriber getSubscriber() { return subscriber; }
Testcode
Subscriber user = new Subscriber(); user.setEmail(email); user.setProfile(new Profile()); user.setIdeal(new IdealProfile());
Session session = HibernateUtil.currentSession(); Transaction tx = session.beginTransaction(); session.save(sub); tx.commit(); HibernateUtil.closeSession();
Can somebody please help me along?
Kind regards,
Marc
|