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

Bug 362913

Summary: Aggregate mappings do not support "isNullAllowed' when aggregate has OneToOneMapping relationships
Product: z_Archived Reporter: hector Ospina <hector.ospina>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: andrei.ilitchev, hector.ospina, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Allow null for AggregateObjectMapping with FK OneToOneMapping
none
Correction to the patch
none
test correction none

Description hector Ospina CLA 2011-11-04 10:27:58 EDT
This issue was discovered when migrating from Toplink to Eclipselink. We have been extensively using this feature in Toplink for over 5 years.


An AggregateMapping does not support the setting of "isNullAllowed" whenever the referenced Aggregate descriptor contains a OneToOneMapping

While I understand there is a complication with supporting collections, I don't believe this restriction should apply to OneToOneMapping

The AggregateObjectMapping.java resets the flag whenever there is a "ForeinReferenceMapping", however this defeats the purpose of OneToOneMappings on aggregates, particularly when the aggregate makes use of flyweight/lookup objects

This probably makes sense for collection type of mappings, when it may be more useful to have an empty collection being returned, while I see no reason why this is not a valid behavior

As a workaround, we implemented an "postLogin" event to reset this behavior back; we are performing extensive testing, but so far we have been OK.

...
        // disallow null for aggregates with relationships
        for (DatabaseMapping mapping:
getReferenceDescriptor().getMappings()){
            if (mapping.isForeignReferenceMapping() ||
mapping.isAbstractCompositeDirectCollectionMapping()){
                isNullAllowed = false;
            }
        }
...

Regards,

Hector Ospina
Comment 1 Tom Ware CLA 2011-11-09 14:14:10 EST
For an aggregate that just contains a 1-1 how can we differentiate between null and an empty reference.

The event you are using tells us you are aware of the restriction and have chosen to deal with it yourself.
Comment 2 Tom Ware CLA 2011-11-17 13:50:48 EST
Closed as WONT FIX based on comment above.
Comment 3 hector Ospina CLA 2011-11-17 14:07:35 EST
(In reply to comment #2)
> Closed as WONT FIX based on comment above.


Tom,
I would kindly ask you to reconsider addressing it.

This workaround is just that, a workaround. 

The behaviour is misleading, because the setting on the workbench is not being honored by the framework. 

We do not understand why a one-to-one mapping on an aggregate cannot support nulls; it's been supported for the past 6 years, at least. 

The change appears to be simple. We need to change the code that resets the flag to still do it for collection type of mappings, and leave it for alone for one-to-one object mappings.


Regards,

Hector
Comment 4 Tom Ware CLA 2011-11-18 09:52:04 EST
Here is the initial bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=289469

This was a design decision related to how we deal with target-key mappings and mappings with a relation table in the default case.  OneToOne Mappings can have target keys and are therefore affected by this fix.
Comment 5 Andrei Ilitchev CLA 2012-02-24 15:54:13 EST
Created attachment 211611 [details]
Allow null for AggregateObjectMapping with FK OneToOneMapping

AggregateObjectMapping allows null if it has ForeignKey OneToOneMapping.
All CollectionMappings as well as ObjectReferenceMappings (such as OneToOne) that use target foreign key still disallow null (mow the warning is logged when that happens).

Test: DDLGenerationJUnitTestSuite.testEmbeddedOneToOne
Comment 6 Andrei Ilitchev CLA 2012-02-24 15:55:53 EST
reopened.
Comment 7 Andrei Ilitchev CLA 2012-02-24 16:32:43 EST
Checked the patch into both 2.4 and 2.3.3
Reviwed by Tom.
Comment 8 Andrei Ilitchev CLA 2012-02-27 09:50:08 EST
Created attachment 211670 [details]
Correction to the patch

In AggregateObjectMapping don't need to do anything if isNullAllowed is false.
In DDLGenerationJUnitTestSuite.testEmbeddedOneToOne made sure that correct table name is used by custom sql on all database platforms.
Comment 9 Andrei Ilitchev CLA 2012-02-27 10:01:14 EST
Checked the correction patch into both 2.4 and 2.3.3
Comment 10 Andrei Ilitchev CLA 2012-03-02 11:29:06 EST
Created attachment 211982 [details]
test correction

When the test runs without weaving id==0 is not accepted, causes ValidationException.
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:28:32 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink