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: 118
Registered: January 2012
Senior Member
Hi Folks..

I have this scenario:

class A {

   @Id
   Integer id;

   @OneToMany(cascade=ALL)
   Set<B> bList;

}

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

    @ManyToOne
    A a;

    @ManyToOne
    C c;

    ... Some other stuff

}

private class C {

    @Id
    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?

Thanks
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: Mon Nov 24 15:32:18 GMT 2014

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

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