-->
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.  [ 6 posts ] 
Author Message
 Post subject: Many-to-one for association to another class
PostPosted: Mon Aug 16, 2004 8:44 am 
Newbie

Joined: Mon Aug 16, 2004 8:36 am
Posts: 7
Location: Canada
Hibernate version:
2.1.6

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

Debug level Hibernate log excerpt:

Hi,

Question from a newbie. The hibernate docs seem to suggest to use a many-to-one to map an association to another class reference (even if that reference really represents a one-to-one association. Can folks confirm this is in fact the way to go?

Secondly, having done the mapping using a many-to-one element to map an assoication with another class. I notice that Hibernate does not attempt to "walk" across this association and persist the associated class. Shouldn't hibernate have the smarts to "walk" across all the different associations mapped this way and attempt to do the persistence (of course I have mappings for all the classes from the associated classes). Is there an attribute or some flag or some option I need to flick on to enable this behaviour. Or do I really have to persist all the associated classes programatically in the context of a hibernate transaction?

Thanks in advance,
Ali


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 9:30 am 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
Confirmed, you can use many-to-one for a foreign key one-to-one mapping. "Works for me."

And yes, you apparently have to insert the dependent first.

_________________
--DP


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 9:33 am 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
To your second question: Have a look at cascade styles. E.g. cascade save-update on an association means that the associated objects are also saved or updated.

Reto


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 9:37 am 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
Gack, My bad, yes, if you cascade='all', then it will automagically save the assocaited object. I didn't write my test properly!

_________________
--DP


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 9:37 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
alimanji wrote:
Or do I really have to persist all the associated classes programatically in the context of a hibernate transaction?

no you don't, that's what hibernate is there for.

maybe post your mapping docs.


Top
 Profile  
 
 Post subject: thanks all folks, this info has been really helpful
PostPosted: Mon Aug 16, 2004 11:14 am 
Newbie

Joined: Mon Aug 16, 2004 8:36 am
Posts: 7
Location: Canada
thanks all folks, this info has been really helpful, much appreciated, cascade seems to be the way to go. Thx.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

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.