Bug 105378

Summary: Session#flushAll mistakenly things a 1..1 association isn't set
Product: [Retired] Red Hat Web Application Framework Reporter: Daniel BerrangĂ© <berrange>
Component: persistenceAssignee: Archit Shah <archit.shah>
Status: CLOSED WONTFIX QA Contact: Jon Orris <jorris>
Severity: medium Docs Contact:
Priority: medium    
Version: nightly   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-11-10 21:03:46 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 108447    

Description Daniel Berrangé 2003-09-25 15:54:00 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 Galeon/1.2.9 (X11; Linux i686; U;) Gecko/20030314

Description of problem:
Consider the following association (i've removed the table mappings for
simplification).

association {
    composite AtoZ[1..1] atoz;
    component AtoZProvider[0..n] atozProviders;
    Integer[0..1] sortKey = atoz_provider_map.sort_key INTEGER;
}


Now, in the code I'm creating an AtoZProvider thus:

  AtoZ atoz = (AtoZ)Kernel.getContext().getResource();
  Assert.exists(atoz, AtoZ.class);
  provider = (AtoZProvider)Classes.newInstance(m_providerType);
  atoz.addProvider(provider);

The addProvider method does this:

    public void addProvider(AtoZProvider provider) {
        add(PROVIDERS, provider);
    }

However, when the transaction commits, the Session#flushAll method throws an
exception:

com.redhat.persistence.FlushException: Unable to send all events to database
because these required properties are null:
 [com.arsdigita.london.atoz.AtoZCategoryProvider:{id=9478}].atoz
        at com.redhat.persistence.Session.flushAll(Session.java:533)
        at com.redhat.persistence.Session.commit(Session.java:619)
        at
com.arsdigita.persistence.TransactionContext.commitTxn(TransactionContext.java:91)
        at
com.arsdigita.kernel.DatabaseTransaction.commit(DatabaseTransaction.java:74)
        at com.arsdigita.kernel.DatabaseTransaction.end(DatabaseTransaction.java:62)

This is bogus, because the code above clearly shows I am setting the association
in question. I have also tried setting the association from the other end, ie
setting 'atoz' explicitly on the AtoZProvider object. This also fails. I have
also tried explicitly setting a value for the link attribute (although since
sortKey is 0..1 its not required). This also has no effect.

 * If I remove the 'sortKey' link attribute this error goes away.
 * Or, ff I change the 'atoz' property to be '0..1' instead of '1..1' the
problem also goes away.

In either case, the 'atoz' property is definitely set to a non-null value since
looking in SQL shows that the mapping table is populated.
So there must be a bug somewhere in the code that checks for nulls that is being
triggered by the link attribute.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. Define an association similar to the above example
2. Run code similar to the above example

    

Additional info:

Comment 1 Archit Shah 2003-10-21 17:58:48 UTC
The bug reported is actually a bug masking a known lacking feature. The reported
bug that is causing the error reported is fixed in 37186. That changes the code
that checks flushability to use the correct metadata. With that fix, the error
you will get is a foreign key violation. The engine is confused by the loop of
1..1 relationships. According to the metadata, the link must exist for the
"provider" object to exist. And the "provider" object, as part of the key of the
link must exist for the link to exist. Only by looking at the physical metadata
and determining that the "provider" object can be created in the database
without the link can this use case work.