-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: EJB - RuntimeExceptions on EntityManager
PostPosted: Thu May 28, 2009 1:36 pm 
Newbie

Joined: Thu May 28, 2009 12:28 pm
Posts: 11
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


Top
 Profile  
 
 Post subject: Re: EJB - RuntimeExceptions on EntityManager
PostPosted: Thu May 28, 2009 2:21 pm 
Newbie

Joined: Thu May 28, 2009 12:28 pm
Posts: 11
Ops, i reread the book carefully, and asked help from a friend and now i get it. System Exceptions does get rolled back. But the second question is: What happened with application exceptions that do not have @ApplicationException(rollback=true)? The transaction stays "iddle" until it expires? The expiration time is up to the container them?

Thks,

Israel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.