users@glassfish.java.net

Re: Help with using container managed with Jax-ws

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 21 Mar 2007 20:33:35 -0700

Hi,

Can you look up EMF in the classes where you currently use
Persistence.createEntityManagerFactory approach? If you do, it will behave the
same way as an injected @PersistenceUnit.

regards,
-marina

glassfish_at_javadesktop.org wrote:
> Hi,
>
> Up to this point, I've been using an application managed transaction.
> I get the entity manager with the following process:
>
> public class wsTransactions{
>
> static{
> emf = Persistence.createEntityManagerFactory("PU");
> }
>
> private static doTransaction(){
> EntityManager em = emf.createEntityManager();
>
> try{
> em.getTransaction().begin();
> em.persist(someEntityObject);
> em.getTransaction().commit();
> }
> finally{
> em.close();
> }
> }
> }
>
> The entityManagerFactory comes from a static class context
>
> static{
> emf = Persistence.createEntityManagerFactory("PU");
> }
>
> The transaction code all sits in static factory classes, like the one above, that I call from different webservices classes.
>
> This seems to work ok, but it seems that the preferred way of handling transactions is by letting the container handle them, and I also have had issues mixing the two different means of handling transactions, most notably a thread death exception.
>
> I've used the annotations ie.
> @Resource
> private UserTransaction utx;
>
> @PersistenceUnit(unitName = "RCCLPU")
> private EntityManagerFactory emf;
> ...
>
> in jsf pages that create the container managed transactions, so i understand how it is done. My goal is to have webservices and jsf pages in the same project share the same persistence unit and have the container manage the transactions. I'm not sure how to do this with jax-ws webservices. I've tried rigging it up by putting a managed bean entry in faces-config.xml and then calling it from the webservice class, but all I get is a null pointer if I try to access it. I'm trying to access the managed bean like this:
>
> FacesContext fc = FacesContext.getCurrentInstance();
> RestaurantsController rc = (RestaurantsController)fc.getExternalContext().getSessionMap ().get("restaurants");
>
> where in this example, restaurants is the name of a managed bean in faces-config.xml
>
> Im using netbeans 5.5 with glassfish v1 final release.
>
>
> Thanks in advance for any help,
> Pat
> [Message sent by forum member 'hollyfeld' (hollyfeld)]
>
> http://forums.java.net/jive/thread.jspa?messageID=209337
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>