-->
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: Newbie: foreign key save
PostPosted: Sun Jan 02, 2005 8:00 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
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


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.