Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Fwd: Bizarre constraint violation

Meant to fwd this to the list as well. 

Begin forwarded message:

From: Noah White <emailnbw@xxxxxxxxx>
Subject: Re: [eclipselink-users] Bizarre constraint violation
Date: September 22, 2014 at 10:25:53 PM EDT
To: Laird Nelson <ljnelson@xxxxxxxxx>

Laird,

Yes, that was my first thought and in fact the original code path was calling some setters on Request. The first thing I did was to move those sets to after the call which creates the new Foo and contains the lookup of Bar that's triggering the constraint violation.  Also because this method is a RequiresNew TX scope I am assuming the entity manager won't contain a scope of anything outside of what's occurring inside of the method. Beers are on me at JavaOne if we can figure this one out :-) 

For reference I am in GF 3.2.1 with the associated Eclipselink from late 2011 I believe. Any thought on how to approach getting more info on the state of the PersistencrContext wrt this (without grabbing the src and stepping thru things :)?

Sent from my iPhone

On Sep 22, 2014, at 5:22 PM, Laird Nelson <ljnelson@xxxxxxxxx> wrote:

That's interesting.  You know, yes—some people don't—that the act of retrieving an object puts it in the persistence context?  So if there's any modification to Request it will be "sent down" to the database, even if naively you thought you were just doing a query.  I'm guessing you know this already but many of my teams over time have been burned by this.

Best,
Laird

On Mon, Sep 22, 2014 at 2:13 PM, Noah White <emailnbw@xxxxxxxxx> wrote:
I’m dealing with EJB 3.1 SSBs which inject a JTA PersistenceContext.  In one of them is a method which is annotated to require a new transaction. Inside that method the code looks up an entity of type Request, then it deletes an entity of type Foo, and then it attempts to create a new entity of type Foo. In the process of creating this new entity of type Foo it performs a named typed query against an entity of Type Bar (eg. SELECT b FROM Bar WHERE b.name=:name).  When the code calls query.getResultSet() and exception is thrown which references a constraint violation on an entity of type Request. Specifically:

java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint (MYDB.REQUEST_FILE_NUMBER) violated - child record found.

From the stack trace its being triggered by the entity manager performing a pre query flush.  The constraint involved is for referential integrity between a Request and a File. The Request object has an optional 1-to-1 unidirectional relationship with File and the constraint is there to ensure the referenced file exists. In this case the Request has a null value for the its File property which should be OK given this is an optional relationship.  A Request is not being merged or persisted it was simply looked up at the start of the TX.

I’m baffled as to why this is being thrown.  Any thoughts are appreciated.

Thanks,

-Noah

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



--
http://about.me/lairdnelson


Back to the top