Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Unique Constraints and Delete and Insert Order - Constraint Violation(Constraint violation removing itens for a list, and adding new)
Unique Constraints and Delete and Insert Order - Constraint Violation [message #1053635] Tue, 07 May 2013 02:23 Go to next message
Eduardo Frazão is currently offline Eduardo FrazãoFriend
Messages: 123
Registered: January 2012
Senior Member
Hi Folks..

I have this scenario:

class A {

   Integer id;

   Set<B> bList;


@UniqueConstraint(a, c)
class B {
    integer id;

    A a;

    C c;

    ... Some other stuff


private class C {

    Integer id;

    ... Some other stuff


Adding new B objects on the A list, everything works.
But, if I remove an B Object from the A list, and adds another, with a C relation equals to the removed object, an UniqueConstraint exception occours because eclipselink try to first insert or update the actual objects, and after, delete.

I read on the documentation that this is the normal behavior, and for now, i'm configuring the UnitOfWork of this transaction to perform deletes before, using the setShouldPerformDeleteFirst property. It works.

But theres no other way that I can configure the UniqueConstraint, that Eclipselink will understand that it needs to perform's delete first? Like configuring some kind of ID relation between the two entities (A and C) over the B mapping?

Re: Unique Constraints and Delete and Insert Order - Constraint Violation [message #1053782 is a reply to message #1053635] Tue, 07 May 2013 14:55 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Your best option is to delete the object, then call flush(), then reinsert it. But in general re-incarnating an object is odd, better to have unique Ids, such as using a generated id.

James : Wiki : Book : Blog : Twitter
Previous Topic:Is UNION supported in a subquery?
Next Topic:Incrementing generated primary key in @PrePersist
Goto Forum:

Current Time: Fri Jun 22 09:45:09 GMT 2018

Powered by FUDForum. Page generated in 0.01995 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top