[jboss-user] [JBoss Seam] - proper usage of persistencecontexts/entitymanagers

balamg do-not-reply at jboss.com
Thu Aug 10 12:27:09 EDT 2006


i have the following code

@Stateful
class Navigator {
    @PersistenceContext (type=EXTENDED)
    EntityManager em;

    List userList = new ArrayList();

    public void init() {
        userList = em.createQuery("select u from User u").getResultList();
    }

    public void addUser(User u) {
        userList.add(u);
    }
}

Then I have another SLSB to add new Users like so:

@Stateless
class ActionBean {
    @PersistenceContext
    EntityManager em;
   
    @In Navigator n;
    
     public void addUser (User u) {
        em.persist(u);
        n.addUser(u);
     }
}

Basically, user saved using one EntityManager (in the slsb) is added to a list that is attached to an extended persistence context.
Is the underlying peresistence context the same ?
This seems to be working fine but wanted to endorse it from the experts.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3964422#3964422

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3964422



More information about the jboss-user mailing list