Hi, i'm a noobie with EJBs, and i'm trying to use a session bean with CMT. But the problem is, the methods of the entityManager (persist,merge,remove...), throws runtimeExceptions, but runtimeExceptions by default are System Exceptions for EJBs (they dont rollback a transaction).
So if i do something like this in my SB:
Code:
em.persist(cat);
em.persist(dog);
em.persist(fish); // RuntimeException for some reason.
does the cat and dog be persisted in the database? if not, does the transaction get rolled back automatically EVEN being a runtimeexception? So, i don't have to think about entityManager exceptions in my EJB, cause them always rollback the transaction automatically?
I find that weird, cause i'm reading EJB-In Action, and it says that only checked exceptions are being rolled-back. I would have to put the @ApplicationException(rollback=true) in the exceptions throw by the entityManager to get this working (and i cant do it). So after all that, I ask you guys, does the following makes sense?
-- Method called in view layer (JSF/Seam component)
Code:
try{
animalBusinessEJB.doALotOfPersists()
} catch (EJBException e) {//fast question: Do I always have to use EJBException catch runtimeExceptions?
//Could i get directly a PersistenceException or ConstraintViolationException (Hibernate Validators)?
facesMessages.add("error" + e.getMessage());
}
-- Stateless SB
Code:
em.persist(cat);
em.persist(dog);
em.persist(fish); // I Dont have to worry cause, exceptions from the entityManager even being runtimeException, automatically rollback the transaction.
--
Is that right?
Thks