users@glassfish.java.net

Re: best way to handling ejb exceptions

From: mSephiroth <moi87g_2_at_yahoo.com>
Date: Wed, 7 Apr 2010 22:34:22 -0700 (PDT)

maybe the question is wrong, what i want to do is to catch the EJBExcepcions
and throws using a exception that i have created. i want in this way because
i want to show to the user the error!

greets


Marina Vatkina-2 wrote:
>
> Try adding em.flush() after em.persist(). The problem you are facing
> (google for
> it - there will be plenty of discussions on that) is that the actual
> database
> insert happens only at commit time, i.e. in the EJB container outside of
> your code.
>
> Keep in mind that calling em.flush() after each em operation can take too
> much
> time if you do it too often in a single transaction.
>
> Regards,
> -marina
>
> mSephiroth wrote:
>> Hi, I dont know if this is the correct forum to post this but i have a
>> situation.
>>
>> Im working on Glassfish v3, jee 6, jsf 2 and netbeans 6.8.
>>
>> I have a package with session beans that access to the database
>> (facades),
>> and a package with session beans that manage the bussines
>> rules(bussines).
>> The situation is when i have a error in the facades beans like duplicated
>> key on the Database, the error is catch by a DataExcepcion create by me,
>> but
>> the excepcion jump until the managedBeans on the web tier and shows and
>> EJBexcepcions, the DataExcepcion dont work, can you tell me a way to
>> handle
>> this exceptions??
>>
>> -------- The facade bean:
>>
>> @Stateless
>> public class SisUsuarioFacade {
>>
>> @PersistenceContext(unitName = "ELearningIATIC_EE-ejbPU")
>> private EntityManager em;
>>
>> public void create(SisUsuario sisUsuario) throws
>> DataAccessLayerException {
>> try {
>> em.persist(sisUsuario);
>> } catch (Exception e) {
>> throw new DataAccessLayerException("Clase: " +
>> SisUsuarioFacade.class.getName() + " Método: create(SisUsuario
>> sisUsuario)");
>> }
>>
>> }
>> }
>>
>> ---------- the Bussines bean
>> @Stateless
>> @LocalBean
>> public class UsuarioServicio {
>> @EJB
>> private SisUsuarioFacade sisUsuarioFacade;
>>
>>
>> public void crearUsuario(SisUsuario usuario, SisRol rolUsuario)
>> throws
>> ServiceLayerException, DataAccessLayerException {
>>
>> sisUsuarioFacade.create(usuario);
>> }
>> .....
>> }
>>
>>
>>
>> thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>

-- 
View this message in context: http://old.nabble.com/best-way-to-handling-ejb-exceptions-tp28159453p28174296.html
Sent from the java.net - glassfish users mailing list archive at Nabble.com.