users@glassfish.java.net

Re: Glassfish / Hibernate Manual transaction demarcation

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Tue, 06 Nov 2007 12:23:00 -0800

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
>