users@glassfish.java.net

Re: Glassfish / Hibernate Manual transaction demarcation

From: Josh Donkersloot <josh_at_geomaxmobile.com>
Date: Thu, 08 Nov 2007 09:50:58 -0600

Thanks,
I will try looking up my remoteDAO after my utx.begin().

Thanks again,
Josh

Marina Vatkina wrote:
> 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
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>