2 Replies Latest reply on Jul 13, 2009 1:52 PM by Julien Kronegg

    EntityManager is closed? why

    John McClain Newbie

      using seam2.0.2sp1 on jboss4.2.0
      I have an entityhome in which I set the Id and get the instance
      here is relevent code:

      @Scope(value = ScopeType.SESSION)
      public class TaxSummaryHome extends EntityHome<TaxSummary> {
           private static final long serialVersionUID = 1L;
           @Out(required = false, scope = ScopeType.SESSION)
           @In(required = false)     
           private SimpleSelection selectedTaxSummaryRows;
           public void setId(Object t)
                TaxSummary h = super.getInstance();
                System.out.println("\nSuperID: " + super.getId()  
                          + "\nID : " + h.getId() 
                          + "\nEntityMgrOpen: " + super.getEntityManager().isOpen() 
                          + "\nmanaged: "  + super.isManaged() 
                          + "\nIDDefined: " + super.isIdDefined());

      The Id is set via a richfaces a4j:support tag attached to a link:

      <h:commandLink action="/tax_summary_item.xhtml" value="#{tax.id}">
      <a4j:support event="onclick" action="#{taxSummaryHome.setId(tax.id)}"/>

      It is getting set correctly as the output of the method looks correct

      SuperID: 55
      ID : 55
      EntityMgrOpen: true
      managed: true
      IDDefined: true

      BUT, when I get to the linked page, and display the status of the entityHome entitymanager, it has changed and is now closed.

      This code

      Item# #{taxSummaryHome.instance.id}  #{taxSummaryHome.entityManager.open} xxx #{taxSummaryHome.idDefined} xxx #{taxSummaryHome.id} xxxxx

      results in this display - notice entityManager.open is now false

      Item# 55  xxx false xxx true xxx 55 xxxxx

      1) since the entitymanager is closed, I get an exception using the {taxSummaryHome.managed} attribute in my xhtml page - This seems like a bug

      2) it will not persist - I get

       javax.persistence.TransactionRequiredException: no transaction is in progress

      Do I have to manually start the transaction, if so how, and why is the entityManager closed  when it moves from the method to the page display?