users@glassfish.java.net

Re: passing entityManagers to helper classes

From: Sahoo <Sahoo_at_Sun.COM>
Date: Fri, 26 Oct 2007 09:48:12 +0530

As long as you access the entity manager in the context of an EJB's
business method call, there is no difference in accessing the entity
manager in an EJB class from a helper class. e.g. following two examples
are same:

Example #1:
@Stateless class FooEJB implements Foo {
 @PersistenceContext EntityManager em;
 public void bar(Object o) {
    em.persist(o);
 }
}

Example #2:
@Stateless class FooEJB implements Foo {
 @PersistenceContext EntityManager em;
 public void bar(Object o) {
    new HelperClass(EntityManager).help(em, o);
 }
}

class HelperClass {
void help(EntityManager em, Object o) { em.persist(o);}
}


Thanks,
Sahoo

glassfish_at_javadesktop.org wrote:
> This is a design qn I have I believe that whenever we try to access entityManager related stuff it should be done within a EJB hence the container manages pooling e.t.c for us but were we to do it in a helper class by passing the entityManager say from a bean to a helper what are the repurcussions
> CHeers
> [Message sent by forum member 'priyasubu' (priyasubu)]
>
> http://forums.java.net/jive/thread.jspa?messageID=242264
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>