This content has been marked as final. Show 2 replies
That's the expected behaviour. If some exception is thrown by the database, the transaction must rollback.
What I generally do to deal with this is to mark the involved methods with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW).
i encapsulated the creating of a single bean in a method annotated @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW). The call of this method is done in a loop and surrounded with try-catch.
At first the entities are stored, but after the constraint violating entity all following entities are not stored in database! No exception is thrown.
If i write entityManager.flush() in the called method, this causes an exception: no transaction is in progress