Skip to main content



      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] Mon, 06 May 2013 22:23 Go to next message
Eclipse UserFriend
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 10:55 Go to previous message
Eclipse UserFriend
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.
Previous Topic:Is UNION supported in a subquery?
Next Topic:Incrementing generated primary key in @PrePersist
Goto Forum:
  


Current Time: Sun Jul 06 08:25:13 EDT 2025

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

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

Back to the top