6 Replies Latest reply on May 4, 2014 6:53 PM by Manan Lalaji

    Location of persistence.xml inside a .war file?

    Stuart White Newbie

      I'm using JBoss AS 6.0.0.M3.  One of the features I'm trying to use is the ability to package EJBs directly within a .war file (without having to place the EJBs in a .jar file).  I also use JPA persistence, and I'm trying to find a place to put persistence.xml inside my .war that JBoss will recognize.  So for I've had no luck.  Is it possible to place persistence.xml (and JPA entity classes) directly in a .war, or do I need to package them as a .jar?

       

      Thanks.

        • 1. Re: Location of persistence.xml inside a .war file?
          jaikiran pai Master

          This might help http://community.jboss.org/wiki/EJB31inAS600M2. Check the section titled "Deployment of EJBs through a .war file"

           

           

          Post edited: I read only the first half of your question. Your real question is not about EJBs but about where to place the persistence.xml file. You can place that file in WEB-INF/classes folder and package the JPA classes in the WEB-INF/classes folder too.


          • 2. Re: Location of persistence.xml inside a .war file?
            Stuart White Newbie

            Hmmm....  I believe that's what I'm doing, but it doesn't seem to be  working.

             

            $ jar tf  dist/offerrepository.war
            META-INF/
            META-INF/MANIFEST.MF
            WEB-INF/
            WEB-INF/classes/
            WEB-INF/classes/org/
            WEB-INF/classes/org/myorg/
            WEB-INF/classes/org/myorg/offerrepository/
            WEB-INF/classes/org/myorg/offerrepository/ejb/
            WEB-INF/classes/org/myorg/offerrepository/jpa/
            WEB-INF/classes/org/myorg/offerrepository/web/
            WEB-INF/classes/org/myorg/offerrepository/ejb/OfferRepositoryBean.class
            WEB-INF/classes/org/myorg/offerrepository/jpa/Offer$Gender.class
            WEB-INF/classes/org/myorg/offerrepository/jpa/Offer.class
            WEB-INF/classes/org/myorg/offerrepository/web/SearchServlet.class
            WEB-INF/classes/persistence.xml
            WEB-INF/web.xml

             

            My EJB injects an EntityManager as such:

             

            @PersistenceContext(unitName = "OfferRepository")
            private EntityManager entityManager;

             

            My  persistence.xml contains this:

             

            <?xml version="1.0" encoding="UTF-8"?>
            <persistence xmlns="http://java.sun.com/xml/ns/persistence"  version="1.0">
                <persistence-unit name="OfferRepository"  transaction-type="JTA">
                    <provider>org.hibernate.ejb.HibernatePersistence</provider>
                    <jta-data-source>java:/OfferRepositoryDS</jta-data-source>
                   <class>org.myorg.offerrepository.jpa.Offer</class>
                   <properties>
                      <property name="hibernate.dialect"  value="org.hibernate.dialect.MySQLDialect" />
                   </properties>
                </persistence-unit>
            </persistence>

             

            And when I deploy to JBoss, I receive this error  message:

             

            DEPLOYMENTS IN  ERROR:
               Deployment  "vfs:///D:/jboss-6.0.0.20100429-M3/server/default/deploy/offerrepository.war"  is in error due to the following reason(s):  java.lang.IllegalArgumentException: Can't find a persistence unit named  'OfferRepository' in  AbstractVFSDeploymentContext@32823696{vfs:///D:/jboss-6.0.0.20100429-M3/server/default/deploy/offerrepository.war}

             

            Any idea what I'm doing wrong?  Thanks for the help.

            • 3. Re: Location of persistence.xml inside a .war file?
              jaikiran pai Master

              Sorry, forgot about this thread. Were you able to fix this? If not, can you please attach a sample application here, which reproduces this problem. Although I haven't checked, I would expect that we have a testcase for this kind of deployments.

              • 4. Re: Location of persistence.xml inside a .war file?
                Zemian Deng Apprentice

                Have you tried placing it like this?

                 

                WEB-INF/classes/META-INF/persistence.xml
                1 of 1 people found this helpful
                • 6. Re: Location of persistence.xml inside a .war file?
                  Manan Lalaji Newbie

                  Thanks a lot .
                  Spent 2 hours figuring it out.