2 Replies Latest reply on Aug 24, 2006 9:12 AM by galo.navarro

    Persistence Manager Exception

    galo.navarro

      JBoss 4.0.4 GA, EJB3 RC8

      Testing EJB3, Stateless & Statefull examples work, my hypersonic database is configured and working, default datasource configured.

      java: Namespace
      
       +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
      


      I'm trying to get an Entity EJB to write something to that datasource but I get the following error:

      17:08:46,983 WARN [ServiceController] Problem starting service jboss.j2ee:service=EJB3,module=entity.ejb3
      java.lang.RuntimeException: Field private javax.persistence.EntityManager org.jboss.tutorial.entity.bean.ShoppingCartBean.manager @PersistenceUnit in error: EMPTY STRING unitName but there is no deployments in scope

      This is my entity bean:

      Order.java

      @Entity
      @Table(name = "PURCHASE_ORDER")
      public class Order implements java.io.Serializable {
      
       private static final long serialVersionUID = 1L;
       private int id;
       private double total;
       private Collection<LineItem> lineItems;
      
      
       public Order() {
       super();
       }
      
       @Id @GeneratedValue(strategy=GenerationType.AUTO)
       public int getId()
       {
       return id;
       }
      


      I use it from a stateless bean that doesn't do much

      package slsb;
      
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import entity.*;
      
      import model.Item;
      
      @Stateless
      public class SimpleStatelessBean implements SimpleStatelessBeanRemote, SimpleStatelessBeanLocal {
      
       @PersistenceContext()
       private EntityManager em;
      
       public Item getItem(Long id) {
       Order o = new Order();
       o.setId(10);
       o.setLineItems(null);
       o.setTotal(100);
       em.persist(o);
       Item item = new Item();
       item.setId(id);
       item.setName("A Java mug");
       return item;
       }
      }
      


      I thought it might be due to a missing persistence.xml file but the error is still the same, this is my persistence.xml, but anyway I didn't think you actually needed this (i've seen examples from the Jboss labs working without them, is it really needed?)

      <persistence>
       <persistence-unit name="BeanExamples">
       <jta-data-source>java:/DefaultDS</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       </properties>
       </persistence-unit>
      </persistence>


      Any suggestions? Thanks

        • 1. Re: Persistence Manager Exception
          holyjoe

          Try replacing the PersistenceContext annotation with

          @PersistenceContext(unitName="BeanExamples")
          


          We had the same error message, and that made it go away, although I don't know why.


          • 2. Re: Persistence Manager Exception
            galo.navarro

             

            "Holy Joe" wrote:
            Try replacing the PersistenceContext annotation with

            @PersistenceContext(unitName="BeanExamples")
            


            We had the same error message, and that made it go away, although I don't know why.


            Thanks, that was the problem actually. As far as I've understood if persistence.xml defines only one unit, this will be used by default and you don't need to specify it in the annotation.

            Now I've got @PersistenceContext alone with this persistence.xml and everything works fine. Thanks for your help.

            <persistence>
             <persistence-unit name="BeanExamples">
             <jta-data-source>java:/DefaultDS</jta-data-source>
             <properties>
             <property name="hibernate.hbm2ddl.auto" value="update"/>
             </properties>
             </persistence-unit>
            </persistence>