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