users@glassfish.java.net

Re: Glassfish / Hibernate Manual transaction demarcation

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 07 Nov 2007 09:30:53 -0800

In this case the container will call em.joinTransaction(), but you can try to
add it after utx.begin() or lookup remoteDAO (is it a SLSB?) after you started
the transaction.

regards,
-marina

Josh Donkersloot wrote:
> My persistence unit transaction-type is JTA. To get my entity manager I
> use
>
> @PersistenceContext
> EntityManager em;
>
> Thanks,
> Josh
>
> Marina Vatkina wrote:
>
>> It really depends... How do you get a hold of an EM and EMF? Is it a
>> JTA or RESOURCE_LOCAL em?
>>
>> thanks,
>> -marina
>>
>>
>> Josh Donkersloot wrote:
>>
>>> Glassfish / Hibernate Manual transaction demarcation
>>>
>>> Hi All,
>>> I am trying to use the following code in a thread that is not managed
>>> by glassfish (it is a callback method that is registered during a
>>> webservice method). The global jndi lookup of both "MyDAORemote" and
>>> the UserTransaction work correctly, and the code runs without any
>>> exceptions, even "myObj" is retrieved correctly using the DAO. The
>>> problem is that the status update to "myObj" is not persisted to the
>>> database, the change is never saved even though I do commit the
>>> transaction. Any help or suggestions would be appreciated. Do I
>>> need to attach the transaction to the entity manager some how?
>>>
>>> Thanks,
>>> Josh
>>>
>>> /***************************************************************/
>>> public void onResult(int resultId) {
>>> try {
>>> //jndi lookup of DAO as this is not a
>>> managed method
>>> Context jndiContext = new javax.naming.InitialContext();
>>> Object remoteDAOObj=
>>> jndiContext.lookup("com.geomaxmobile.dao.MyDAORemote");
>>> MyDAORemote remoteDAO = (MyDAORemote) remoteDAOObj;
>>> //jndi lookup of usertransaction
>>> Object utObject =
>>> jndiContext.lookup("java:comp/UserTransaction");
>>> UserTransaction tx = (UserTransaction) utObject;
>>> tx.begin();
>>> MyObject myObj= remoteDAO
>>> .findById(resultId, false);
>>> myObj.setStatus("Done");
>>>
>>> //commit the transaction
>>> tx.commit();
>>> } catch (Exception e) {
>>> e.printStackTrace(); }
>>> }
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>