At persist()
there is a lock over the table/row (well, that is configurable), and for some reason the Tx can not be rollback because of that... until the timeout arrives.
How looks the Department
entity?, match correctly to the table?, and how is the generated sql insert
by the ORM?
At least the EJB code looks ok and if you are sure that the entity correctly maps the table, you can focus at database/ORM with its locks.
Option: Sometimes instead of setRollback, I would suggest to throw a runtimeException (IllegalStateException
, IllegalArgumentException
or a custom), the container will mark automatically for rollback the Tx (and exit as soon as possible from the method), this would make your code more expressive .