4 Replies Latest reply on Sep 25, 2008 2:35 PM by nimo stephan

    Seams EntityManager...

    nimo stephan Master

      I have the following Scenario:

      SessionBean A, EntityBean B, ManagedBean C (POJO for my view).

      ONLY in A, I have injected Seams EntityManager:

      public class A implements aLocal {
      EntityManager entityManager;

      In my View-Bean C, I inject the Interface aLocal and a Instance of B:

      public class C {
      //retrieves methods from aLocal
      aLocal alocal;
      @In(required=true) @Out (required = false)
      private B b;
        public void changeB {

      all works perfectyl, BUT:

      My Seam-managed EntityManager does automatically make a database-operation when I do something like


      even when I do NOT have explicitly inject a EntityManager in my ManagedBean C or call the method


      As I have no entityManager in C available, I cannot do something like:

      if (entityManager.isOpen())
       { //detach the Entity-Instance} }

      I absolutely want avoid, to inject a EntityManager into a web component (in my case the managedBean C).

      Another point is, when I do in my EntityBean B something like:

      public class B implements Serializable{
      private String name;
      public String getName() {
              return name.trim();

      and call anywhere this getter, then the database-operation UPDATE NAME FROM B is made. Why?

      I do not have call the merge/persist-Method nor I have no entityManager-Instance (in my view-bean).

      Have it to do with call by value and call by reference or with Seams (implicitly extended) EntityManager?? Have it to do with my packaging? I have used SEAM-Gen to generate my EJB-Project.

      I want that my WARs are managed by the servlet-container (having no direct access to the EJBs entityManager, and my EARs (sessionBeans, entityBeans) should be managed by the EJB-Container (having access to the entityManager).

      I need the instance from a entity-Bean and change the values only when I do explicitly want it (with methods such as persist, merge,..).

      Any Ideas?