Community
Participate
Working Groups
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
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.
Closed as WONT FIX based on comment above.
(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
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.
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
reopened.
Checked the patch into both 2.4 and 2.3.3 Reviwed by Tom.
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.
Checked the correction patch into both 2.4 and 2.3.3
Created attachment 211982 [details] test correction When the test runs without weaving id==0 is not accepted, causes ValidationException.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink