5 Replies Latest reply on Jul 25, 2007 12:30 PM by tigrik

    Jboss can't find annotated entity classes

    tigrik

      Hi guys, I'm new to EJB3 so maybe it's a real dumb question but I'm sitting 3 days with this error right now and slowly becoming crazy.

      The problem is, JBoss 4.2 can't find my entity classes. As it starts the persistence I get an error (see bellow).

      Here is my persistence.xml:



      <persistence-unit name="database" transaction-type="RESOURCE_LOCAL">
      <jta-data-source>java:/MySqlDS</jta-data-source>






      </persistence-unit>



      mysql-ds.xml is OK and JBoss reads it. It's called MySqlDS in JNDI.

      So the problem is, when I do:


      entityManagerFactory = Persistence.createEntityManagerFactory("database", new HashMap());

      I get this error:

      17:36:23,060 INFO [Version] Hibernate EntityManager 3.2.1.GA
      17:36:23,083 INFO [Version] Hibernate Annotations 3.2.1.GA
      17:36:23,108 INFO [Environment] Hibernate 3.2.4.sp1
      17:36:23,117 INFO [Environment] hibernate.properties not found
      17:36:23,119 INFO [Environment] Bytecode provider name : javassist
      17:36:23,124 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
      17:36:23,436 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      javax.persistence.PersistenceException: [PersistenceUnit: database] class or package not found
      at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1089)
      at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:886)
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:772)
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)
      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
      at com.kukinbuk.utils.EntityManagerFilter.doFilter(EntityManagerFilter.java:53)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.ClassNotFoundException: WEB-INF.classes.com.kukinbuk.hibernate.RecipePicture
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:247)
      at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:112)
      at org.hibernate.ejb.Ejb3Configuration.classForName(Ejb3Configuration.java:1005)
      at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1077)
      ... 26 more

      It happends with every single Class I annotate as @entity. The classes are deffinitely there in my WAR-Archive und same names... Here an example of such a class (generated by Eclipse 3.3 using latest Hibernate Tools)

      package com.kukinbuk.hibernate;
      // default package
      // Generated 24.07.2007 19:50:34 by Hibernate Tools 3.1.0.beta5

      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.Table;

      /**
      * RecipePicture generated by hbm2java
      */
      @Entity
      @Table(name = "recipe_picture", catalog = "kukinbuk", uniqueConstraints = {})
      public class RecipePicture implements java.io.Serializable {

      // Fields

      private long id;
      private Recipe recipe;
      private String picture;
      private String title;

      // Constructors

      /** default constructor */
      public RecipePicture() {
      }

      /** minimal constructor */
      public RecipePicture(long id) {
      this.id = id;
      }

      /** full constructor */
      public RecipePicture(long id, Recipe recipe, String picture, String title) {
      this.id = id;
      this.recipe = recipe;
      this.picture = picture;
      this.title = title;
      }

      // Property accessors
      @Id
      @Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true)
      public long getId() {
      return this.id;
      }

      public void setId(long id) {
      this.id = id;
      }

      @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
      @JoinColumn(name = "RECIPE_ID", unique = false, nullable = true, insertable = true, updatable = true)
      public Recipe getRecipe() {
      return this.recipe;
      }

      public void setRecipe(Recipe recipe) {
      this.recipe = recipe;
      }

      @Column(name = "PICTURE", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
      public String getPicture() {
      return this.picture;
      }

      public void setPicture(String picture) {
      this.picture = picture;
      }

      @Column(name = "TITLE", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
      public String getTitle() {
      return this.title;
      }

      public void setTitle(String title) {
      this.title = title;
      }

      }

        • 1. Re: Jboss can't find annotated entity classes
          tigrik

          peristance.xml:

          <persistence>
          
           <persistence-unit name="database" transaction-type="RESOURCE_LOCAL">
           <jta-data-source>java:/MySqlDS</jta-data-source>
           <properties>
           <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
           <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
           </properties>
          
          
          </persistence-unit>
          
          
          
          </persistence>


          • 2. Re: Jboss can't find annotated entity classes
            jaikiran

             

            Caused by: java.lang.ClassNotFoundException: WEB-INF.classes.com.kukinbuk.hibernate.RecipePicture


            Looks like the class name is incorrect.



            • 3. Re: Jboss can't find annotated entity classes
              tigrik

               

              "jaikiran" wrote:
              Caused by: java.lang.ClassNotFoundException: WEB-INF.classes.com.kukinbuk.hibernate.RecipePicture


              Looks like the class name is incorrect.



              JBoss searches for @entity marked classes itself... so how the class name can be wrong, it's what JBoss found?

              Maybe it's just impossible to use EJB3 in WAR file and I have to create some EAR App?

              • 4. Re: Jboss can't find annotated entity classes
                waynebaylor

                have you tried adding the entities to your persistence.xml?

                <persistence>
                
                 <persistence-unit name="database" transaction-type="RESOURCE_LOCAL">
                 <jta-data-source>java:/MySqlDS</jta-data-source>
                
                 <!-- LIST ENTITIES HERE -->
                 <class> com.kukinbuk.hibernate.RecipePicture</class>
                
                 <properties>
                 <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                 </properties>
                
                
                </persistence-unit>
                
                
                
                </persistence>


                • 5. Re: Jboss can't find annotated entity classes
                  tigrik

                   

                  "waynebaylor" wrote:
                  have you tried adding the entities to your persistence.xml?




                  Yes I did! Seams like it's impossible to hold the EJB3 in the WAR. You have to make EAR with WEB-content in WAR and EJB3 in some JAR file... No idea how to do it using Eclipse... :(