JPA ConstraintViolation vs Rollback

后端 未结 2 1929
后悔当初
后悔当初 2020-12-19 14:18

I think I just found that two different JPA implementations work differently for constraint violations and rolling-backs.

         


        
2条回答
  •  心在旅途
    2020-12-19 15:06

    Both are correct. JPA allows providers to throw EntityExistsException at persist or another PersistenceException at flush/commit, which I have always assumed cover database exceptions. I don't know Hibernate or the full error you are getting, but I guess that the database exception is occuring and gets wrapped in a RollbackException.

    The two tests might not be equivalent though - ConstraintViolationException is not coming from JPA but from validation (JSR-303) that occurs during prepersist. You must have a bean validation implementation enabled in the EclipseLink test (such as hibernate-validator-4.0.1.GA.jar on the classpath) that might not be enabled in the Hibernate tests. If you remove bean validation from one or add it to the other, they should behave more similar.

提交回复
热议问题