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
>