How to prevent Hibernate from throwing ConstraintViolationException when using session.saveOrUpdate(Object)?

230 views Asked by At

ConstraintViolationException is being thrown by hibernate when I use session.saveOrUpdate(Object). Shouldn't the "update" part prevent this excpetion from being thrown?

I have also tried using session.delete(Object) and then session.save(Object) but the same exception is thrown. How would I fix this?

1

There are 1 answers

0
Robert Li On BEST ANSWER

Adding this annotation to the entity solved the issue:

@SQLInsert(sql="REPLACE INTO table_name (column_1,column_2) VALUES (?,?)")