7 Replies Latest reply on Oct 12, 2007 5:44 PM by pmuir

    JAR with entities in a WebApp

    yuriy_zubarev

      Hello,

      I'm trying to set up Seam (2.0.0) Web App under Tomcat 6.0 in a such a way as to have 2 POM project. One is with entities (@Entity) and another one is a web app itself (and there is a parent POM of course). The idea is that entities could be re-used between different sub-projects.

      He is my structure:

      .
       |-- pom.xml
       |
       |-- entity
       | |-- pom.xml
       | |-- src
       | |-- main
       | |-- java
       | | |-- entitypackage
       | | |-- Book.java
       | |-- resources
       | |-- seam.properties
       |
       |-- webapp
       |-- pom.xml
       |-- src
       |-- main
       |-- java
       | |-- webpackage
       | |-- BookController.java
       |-- resources
       | |-- seam.properties
       |-- webapp
       |-- META-INF
       | |-- context.xml
       | |-- persistence.xml
       |-- WEB-INF
       |-- web.xml
       |-- components.xml
       |-- pages.xml
      


      In BookController I have something like this:

      this.books = em.createQuery("select b from entitypackage.Book b").getResultList();
      


      When the web app is running this is what I see in a log file:

      WARNING: no persistent classes found for query class: select b from entitypackage.Book b
      


      When I move Book.java to webapp project, everything works like a charm. I also tried to provide persistence.xml under entity/META-INF and provide "class" element in there but it didn't help.

      I was wondering how I can separate entity (and java beans/session) classes from the actual web application and still enjoy the benefits of Seam. Just to stress it again, I'm building a light-weight web app to be run under Tomcat without EJB embedded container.

      Thank you.
      Yuriy


        • 1. Re: JAR with entities in a WebApp
          pmuir

          What is the structure of the archives when deployed?

          • 2. Re: JAR with entities in a WebApp
            yuriy_zubarev

            It looks like this:

            webapp
             |-- META-INF
             | |-- persistence.xml
             | |-- context.xml
             |-- WEB-INF
             |-- web.xml
             |-- components.xml
             |-- pages.xml
             |-- classes
             | |-- seam.properties
             | |-- webpackage
             | |-- BookController.class
             |-- lib
             |-- entity.jar
            


            Thank you,
            Yuriy


            • 3. Re: JAR with entities in a WebApp
              yuriy_zubarev

              entity.jar is under lib folder of course.

              • 4. Re: JAR with entities in a WebApp
                pmuir

                Surely persistence.xml should be in the entity jar?

                • 5. Re: JAR with entities in a WebApp
                  yuriy_zubarev

                  Ok I got it. I had persistence.xml both in entity.jar and under META-INF of the webapp. As soon as I removed it from webapp the app started working.

                  Thank you,
                  Yuriy

                  • 6. Re: JAR with entities in a WebApp
                    yuriy_zubarev

                    At the same time. This is not flexible enough. If entity.jar gets distributed everywhere with its own persistence.xml that looks something like this:

                    <?xml version="1.0" encoding="UTF-8"?>
                    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                     version="1.0">
                    
                     <persistence-unit name="coolDatabase"
                     transaction-type="RESOURCE_LOCAL">
                     <provider>org.hibernate.ejb.HibernatePersistence</provider>
                     <jta-data-source>java:comp/env/jdbc/CoolDB</jta-data-source>
                     <class>entitypackage.Book</class>
                     <properties>
                     <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                     <property name="hibernate.show_sql" value="true" />
                     <property name="hibernate.cache.provider_class"
                     value="org.hibernate.cache.HashtableCacheProvider" />
                     </properties>
                     </persistence-unit>
                    </persistence>
                    


                    then every system would "inherit" and would have to respect names like "coolDatabase", hibernate.hbm2ddl.auto would always be set to true and so on.

                    What I would like is to keep my entities separately from rules on how they could be used. Is it possible somehow?

                    Thank you.
                    Yuriy


                    • 7. Re: JAR with entities in a WebApp
                      pmuir

                      You should ask this question in the hibernate jpa forum.