-->
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.  [ 4 posts ] 
Author Message
 Post subject: M-1 updates
PostPosted: Fri Nov 26, 2004 1:57 am 
Newbie

Joined: Wed Nov 24, 2004 10:15 am
Posts: 7
Hibernate version:2.1.7

Mapping documents:
<many-to-one name="contact" class="com.palantir.db.SLContact" cascade="save-update" column="ENTITYID" not-null="true"/>

<many-to-one name="contact" class="com.palantir.db.SLContact" cascade="save-update" column="ENTITYID" not-null="false"/>


The Problem
When I use not-null='false' the engine issues three statements to update a parent child relationship (two inserts and an update for the key).

When I use not-null='true' the engine issues an insert and a PropertyValueException. It does not set the foreign key. Is there any way of declaring a unidirectional relationship that updates using two statements. I have read chapter 16 which only covers bidirectional relationships. That chapter seems to indicate that using not-null should change the behaviour to two insert statements, which is how it should be.

Debug level Hibernate log excerpt:
Code:
2004-11-25 10:40:00,520 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: hibernate/HibernateFactory
2004-11-25 10:40:00,520 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=8ae496f7006edfbb01006ee2ea170001
2004-11-25 10:40:00,520 DEBUG [net.sf.hibernate.impl.SessionImpl] opened session
2004-11-25 10:40:00,581 DEBUG [net.sf.hibernate.impl.SessionImpl] saving [com.palantir.db.SHStakeholder#<null>]
2004-11-25 10:40:00,581 DEBUG [net.sf.hibernate.impl.SessionImpl] executing insertions
2004-11-25 10:40:00,581 DEBUG [net.sf.hibernate.engine.Cascades] processing cascades for: com.palantir.db.SHStakeholder
2004-11-25 10:40:00,581 DEBUG [net.sf.hibernate.engine.Cascades] cascading to saveOrUpdate()
2004-11-25 10:40:00,581 DEBUG [net.sf.hibernate.impl.SessionImpl] saveOrUpdate() unsaved instance
2004-11-25 10:40:00,681 DEBUG [net.sf.hibernate.impl.SessionImpl] generated identifier: 653502
2004-11-25 10:40:00,681 DEBUG [net.sf.hibernate.impl.SessionImpl] saving [com.palantir.db.SLContact#653502]
2004-11-25 10:40:00,681 DEBUG [net.sf.hibernate.engine.Cascades] done processing cascades for: com.palantir.db.SHStakeholder
2004-11-25 10:40:00,721 ERROR [STDERR] net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.palantir.db.SHStakeholder.SLContact


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 3:29 am 
Newbie

Joined: Wed Nov 24, 2004 10:15 am
Posts: 7
Hi All,

Should I perhaps include this as a bug for the next release of hibernate.
I think it must be a bug if it works with not-null false, and not with not-null true.

What do you think?
It must be a bug, because I have had very few responses.
It is quite alarming that hibernate cannot cascade M-1 relationships that are unidirectional and have referential integrity.

Regards
Craig.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 8:21 am 
Regular
Regular

Joined: Tue Oct 26, 2004 3:54 pm
Posts: 60
To help sort out cascading problems (I had one similar to yours), I recommend you to read this :

http://www.hibernate.org/155.html

Following that example, I had no problems in defining a many-to-one relation with not-null FKs.


Giulio Vezzelli


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 8:36 am 
Newbie

Joined: Wed Nov 24, 2004 10:15 am
Posts: 7
Hi,

I read some of the article you have suggested.
In the meantime I have implemented Lifecycle in each of the objects, and call save and update in the onSave of the parent. This ensures that the cascade works correctly without having to second guess what hibernate thinks it should do with the dependent classes.

I suspect the hibernate default behaviour is designed with bi-directional relationships in mind (at least one inverse=true) in the relationship.


Thanks

Regards
Craig


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.