7 Replies Latest reply on Jul 7, 2010 3:25 AM by jaikiran pai

    Hibernate entities are not automatically scanned

    alex soto Newbie

      Looks like with JBoss 5.1.0.GA I am forced to declare each entity class in the persistence.xml file using the <class> tag.

      If not explicitly declared, I get errors saying that the entity is not mapped.

       

      I am migrating my project from 4.2.2.GA and I did not have to do this.

       

      My environment is:

       

           JBoss 5.1.0.GA

           Hibernate 3.3.2.GA

           Java 6.

       

      My application is:

       

           A EAR file containing a EJB JAR file, and a data source file "*-ds.xml"

       

      The EJB jar file contains a persistence.xml referencing the datasource defined at the EAR level.

      The entity classes are contained in the EJB JAR file.

       

      How can I avoid having to do this?

      Isn't the EJB3 deployer supposed to scan all classes and map the annotated entities?

      I have a lot of annotated entity classes and I don't want to maintain this by hand.

       

      Thanks,

      Alex

        • 1. Re: Hibernate entities are not automatically scanned
          jaikiran pai Master

          You don't have to explicitly map the entitites in the persistence.xml. Where exactly have you placed the persistence.xml (within the EJB jar)? And please post a sample Entity class (including the annotation and the import statements).

          • 2. Re: Hibernate entities are not automatically scanned
            alex soto Newbie

            Hello Jaikiran,

            Thank you for the reply.

             

            My persistence.xml is in the META-INF directory of the EJB jar.

            My entities look like this:

             

            import javax.persistence.Column;

            import javax.persistence.Entity;

            import javax.persistence.GeneratedValue;

            import javax.persistence.Id;

            import javax.persistence.Table;

             

            @Table(name="TBL_AFFILIATES")

            @Entity(name="Affiliate")

            public class Affiliate implements java.io.Serializable {

             

            ....

             

            I hope this helps. Let me know if you need more information.

            Are there log4j categories I need to tweak to help troubleshot this?

            I was also trying to find the example apps in the JBoss downloads section but could find any sample app to compare.

            The documentation talks about a TODO application, where can I find it?

             

            Thanks,

            Alex Soto

            • 3. Re: Hibernate entities are not automatically scanned
              jaikiran pai Master

              alex soto wrote:

               

              My persistence.xml is in the META-INF directory of the EJB jar.

              My entities look like this:

               

              import javax.persistence.Column;

              import javax.persistence.Entity;

              import javax.persistence.GeneratedValue;

              import javax.persistence.Id;

              import javax.persistence.Table;

               

              @Table(name="TBL_AFFILIATES")

              @Entity(name="Affiliate")

              public class Affiliate implements java.io.Serializable {

               

              ....

               

              I don't see any obvious reason why this won't work. The code and the location of the file looks fine. Can you also post the persistence.xml file? Also are you packaging any hibernate jars or any jar file(s) containing javax.persistence.* in your application? If yes, then try removing those.

               

              alex soto wrote:

               

              Are there log4j categories I need to tweak to help troubleshot this?

              Changing org.hibernate category to something like DEBUG might help.

               

              alex soto wrote:

               


              I was also trying to find the example apps in the JBoss downloads section but could find any sample app to compare.

              The documentation talks about a TODO application, where can I find it?

               


               

              The TODO example no longer exists, AFAIK. We however do have some tutorials here http://jboss.org/ejb3/docs

              • 4. Re: Hibernate entities are not automatically scanned
                alex soto Newbie

                I found what the problem is:

                 

                If the data source file (ecomm-ds.xml) is in the deploy directory (outside of the EAR) it works.

                If the datasource is included inside the EAR file, then it does not work.

                 

                I was trying to get the data source deployed as part of the EAR. 

                My "META-INF/jobss-app.xml" looks like this:

                 

                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE jboss-app PUBLIC
                "-//JBoss//DTD Java EE Application 5.0//EN"
                "http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd">
                <jboss-app>
                  <module>
                    <service>ecomm-ds.xml</service>
                  </module>
                </jboss-app>
                

                 

                The ecomm-ds.xml file is in the root of the EAR.

                Am I doing something wrong?

                 

                 

                Thanks,

                Alex Soto

                • 5. Re: Hibernate entities are not automatically scanned
                  jaikiran pai Master

                  That should have worked. Are there any error/exceptions when it doesn't work? Also please post the persistence.xml file.

                  • 6. Re: Hibernate entities are not automatically scanned
                    alex soto Newbie

                    There are no evident errors that I could notice.

                    Attached is my persistence.xml file.

                    • 7. Re: Hibernate entities are not automatically scanned
                      jaikiran pai Master

                      I think I know what the issue is. But I would have expected an exception/error during the deployment. So I am not 100% sure of what's going on. Please attach your server.log for both the cases (one where you see the issue and the other where you explicitly specify the classes).