Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 321197 - Support Mandatory One-To-One relations with Hibernate
Summary: Support Mandatory One-To-One relations with Hibernate
Status: NEW
Alias: None
Product: EMF
Classification: Modeling
Component: Teneo (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Martin Taal CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-29 05:28 EDT by Hans Meier CLA
Modified: 2010-07-29 15:46 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hans Meier CLA 2010-07-29 05:28:04 EDT
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
Comment 1 Hans Meier CLA 2010-07-29 15:46:31 EDT
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.