Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328749

Summary: A false boolean value is not populated into an EObject when using the Hibernate merge() API
Product: [Modeling] EMF Reporter: Nikita <d.nikita.e>
Component: TeneoAssignee: Martin Taal <mtaal>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Nikita CLA 2010-10-26 13:45:48 EDT
Build Identifier: org.eclipse.emf.teneo-1.1.2-v201007191154

I have an EClass which has a boolean field. Using the session.merge() method, I persist a value for which the boolean field is set to false. In the EObject returned by the merge() method, the boolean field is set to null.

I think this happens because of the following:
 * In org.eclipse.emf.teneo.hibernate.mapping.property.EAttributePropertyHandler, in the set() method, Teneo first retrieves the current value of the field that's about to be set.
 * If the current value is the same as the new value that came back from the DB, Teneo skips setting the field.
 * The problem is that, for a boolean field, retrieving the current value gives the value false, even when the actual field value is null. This is because there is logic in org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.InternalSettingDelegateSingleData (line 1962) which says if the value of the field is null, return the defaultValue (which for boolean is false).

Reproducible: Always

Steps to Reproduce:
1. Define an EClass that has a boolean field (xsd:boolean when generating Ecore from XSD).
2. Using the merge() API, persist an instance of the type that has a false boolean value. The value is written to the DB, but the EObject returned by the merge() call will have the value null in the boolean field.
Comment 1 Nikita CLA 2010-10-26 13:49:04 EDT
I added a test case in Assembla (r74).
Comment 2 Martin Taal CLA 2010-10-29 08:31:09 EDT
Hi,
A solution for non-eav cases has been committed to cvs and will be in the next build. 

Another issue I found is that merge does not work for EAV, I will send a separate email on this.
Note that EMF default value handling is a bit specific (as you noted), see this lengthy discussion thread on the topic:
http://www.eclipse.org/forums/index.php?t=tree&th=161533&

gr. Martin