Announcement Announcement Module
No announcement yet.
[Roo + GWT] Duplicate entry 'xxxx' for key 'name' (JDBCExceptionReporter) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Roo + GWT] Duplicate entry 'xxxx' for key 'name' (JDBCExceptionReporter)


    In application made with Roo (1.2.0.M1) + GWT, when client fire the creation or the update of an entity with ConstraintViolation, the Receiver got an onConstraintViolation call.

    It's ok with field size, notnull constraints but not unique constraint.

    With unique constraint, annotate with "@Column(unique = true)", Receiver get a "onSuccess(Void void)" call with no way to know that the persistence is in error.

    Is there a way to get an onConstraintViolation in case of Duplicate entry DB error ?


  • #2
    JSR303 is not implementing uniqueness validation

    OK it's not as simple as this because JSR303 is not implementing uniqueness validation.
    Why : because between the check and the persist call someone else can persist a similar entity and make you get a "Duplicate entry" error.

    What can we do ?
    Create a JSR 303 style unique value annotation checking there is no table entry with same value.

    This is a good solution ?
    No, there is no real good solution except getting a lock on the table between check and persist, but seem to be a performance bad solution.

    So ?
    It's better than nothing. You will be in trouble only in case of double persist entity with same unique values. Depend and your application but seem to be rare.

    Links about creating a JSR 303 style unique value annotation :

    If you have other examples, feel free to give it !