1 Reply Latest reply on Jan 16, 2007 8:04 AM by wolfgangknauf

    No default persistence unit in this deployment

    lalit2583

      Following is the Session bean and entity class...


      Session1Bean.java
      package com.jboss.sessionbeans;

      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;

      import com.jboss.entity.Login;

      public @Stateless class Session1Bean implements Session1 {

      @PersistenceContext(name="demo")
      private EntityManager em;
      public void add(int userId, String password) {
      Login lg = new Login();
      lg.setUserId(12);
      lg.setPassword("password");
      em.persist(lg);
      System.out.println("The value is persist ");
      }

      }


      Login.class

      package com.jboss.entity;

      import java.io.Serializable;

      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;

      @SuppressWarnings("serial")
      @Entity
      public class Login implements Serializable{

      private int userId;
      private String password;

      @Column(name="PASSWORD")
      public String getPassword() {
      return password;
      }
      public void setPassword(String password) {
      this.password = password;
      }
      @Id
      @GeneratedValue
      @Column(name="USERNAME")
      public int getUserId() {
      return userId;
      }
      public void setUserId(int userId) {
      this.userId = userId;
      }
      public String toString() {
      return Integer.toString(userId);
      }
      }


      I have Persistence.xml as follows...
      <?xml version="1.0" encoding="UTF-8"?>

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


      I have speciied all the things in persistence.xml these--> is used as marking it is not present in actual code
      persistence.xml is inside META-INF folder...


      Following is the error I am getting......



      --- MBeans waiting for other MBeans ---
      ObjectName: jboss.j2ee:service=EJB3,module=Demo3.jar
      State: FAILED
      Reason: java.lang.RuntimeException: Illegal @PersistenceUnit on private javax.
      persistence.EntityManager com.jboss.sessionbeans.Session1Bean.em :There is no de
      fault persistence unit in this deployment.

      --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
      ObjectName: jboss.j2ee:service=EJB3,module=Demo3.jar
      State: FAILED
      Reason: java.lang.RuntimeException: Illegal @PersistenceUnit on private javax.
      persistence.EntityManager com.jboss.sessionbeans.Session1Bean.em :There is no de
      fault persistence unit in this deployment.