Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Failed insert results in invalid cache state

Definitely a tricky thing to do.  Try not cloning the object, as this will
violate object identity, just set its id to null and re-execute the query.

What does your error handler do exactly?

I assume you are using JPA/UnitOfWork?



bryans wrote:
> 
> Here's my situation:
> 
> I'm trying to determine if it's possible to retry an insert when it fails
> due to PK collision. (Please don't ask why, just go with it).
> 
> So i've got my own ID Generator which assigns the ID of 1 to every entity.
> I've also built a ExceptionHandler to deal with the collision error.
> 
> In the error handler i've good logic to clone the failed insert object,
> without the old PK. I update the ID generator's next value to 2. Then i
> just re-execute the query (which assigns the new ID). 
> 
> I then execute my tests (JUnit methods), before each of them i delete the
> database contents to ensure a clean slate:
> 
> 1) ID Collision insert on single executable statement w/ retry disabled -
> # Records in DB = 1 - Correct
> 2) ID Collision insert on single executable statement w/ retry enabled - #
> Records in DB = 2 - Correct
> 3) ID Collision on 4th statement after 3 successful inserts (parent,
> child, grandchild, great-grandchild<-Collision) w/retry disabled - # Of
> records in DB 0 - Correct 
> 
> But if i do a "find" on the ID for the parent, i get back the failed
> inserted object from test #2. The database still has 0 contents because
> the whole transaction was rolled-back.
> 
> Can someone tell me why the cache has failed insert objects in it, and/or
> how to clear them before i attempt my retries?
> 
> Any help is much appreciated, and my thanks in advance.
> 
> -B
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Failed-insert-results-in-invalid-cache-state-tp25384148p25388886.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top