Community
Participate
Working Groups
Build Identifier: 20100617-1415 Persisting a model with mandatory bidirectional references in Hibernate results in "org.hibernate.PropertyValueException: not-null property references a null or transient value: Head.animal" Reproducible: Always Steps to Reproduce: Please see http://www.eclipse.org/forums/index.php?t=tree&th=172735
I did some further investigations on this issue. The problem is the combination of cascade="all" and constrained="true" in the one-to-one tag of generated hibernate mapping. <hibernate-mapping auto-import="false"> <class name="demo.impl.AnimalImpl" entity-name="Animal" abstract="false" lazy="false" table="`Animal`"> <meta attribute="eclassName">Animal</meta> <meta attribute="epackage">http://demo</meta> <id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler"> <meta attribute="syntheticId">true</meta> <generator class="native"/> </id> <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler"> <meta attribute="syntheticVersion">true</meta> </version> <one-to-one name="head" entity-name="Head" cascade="all" lazy="false" property-ref="animal" constrained="true"/> </class> <class name="demo.impl.HeadImpl" entity-name="Head" abstract="false" lazy="false" table="`Head`"> <meta attribute="eclassName">Head</meta> <meta attribute="epackage">http://demo</meta> <id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler"> <meta attribute="syntheticId">true</meta> <generator class="native"/> </id> <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler"> <meta attribute="syntheticVersion">true</meta> </version> <many-to-one name="animal" entity-name="Animal" cascade="merge,persist,save-update,lock,refresh" not-null="true" lazy="false" insert="true" update="true" unique="true"/> </class> </hibernate-mapping> To me this looks like a bug in hibernate. But since the underlying ORM should be transparent to the Teneo users a workaround is needed. E.g. by setting the constrained="true" to "false" and doing the validation of the mandatory 1-1 reference in Teneo some how.