9 Replies Latest reply on Apr 16, 2018 5:06 AM by mayerw01

    Can't find persistence unit named in deployment

    skorejo

      Hi all,

       

      I am getting this error while starting Wildfly server (version 12).  I do have a persistence.xml with persistence unit. What am i doing wrong in the below code? It was working fine with Glassfish.

       

      Error:

       

      Component class my.package.services.ClassAFacade for component ClassAFacade has errors:

      WFLYJPA0033: Can't find a persistence unit named war_PU in deployment "\my.war\"

       

      ClassAFacade:

       

      @PersistenceContext(unitName = "war_PU" )

      private EntityManager em;

       

      persistence.xml:

       

      <xml version="1.0" encoding="UTF-8"?>

      <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://java.sun.com/xml/ns/persistence  http://java.sun.com/xml/ns/persistence/persistence_2.0.xsd">

      <persistence-unit name="war_PU" transaction-type="JTA"></provider>

      <jta-data-source>java:/jdbc/mydb</jta-data-source>

      <class>my.package.entities.ClassA</class>

      <exclude-unlisted-classes>false</exclude-unlisted-classes>

      <properties>

      <property name="eclipselink.logging.level" value="INFO"/>

      </properties>

      </persistence-unit>

      </persistence>

       

      Kind Regards,

      Sana

        • 1. Re: Can't find persistence unit named in deployment
          jewellgm

          Do you have a datasource defined in your standalone.xml with a jndi-name of "java:/jdbc/mydb"?

           

          Where is your persistence.xml bundled in relation to ClassAFacade?

           

          It also looks like you have malformed XML.  I see a "</provider>", but no opening tag.

          • 2. Re: Can't find persistence unit named in deployment
            skorejo

            Yes it is there in standalone-full.xml which is getting used in my case.

             

            commondaoproject

            |_Source packages

                 |_my.package.services

                          |_ ClassAFacade.java

            |_Other sources

                 |_ resources

                      |_ META-INF

                           |_ cg91

                                |_ persistence.xml

             

            I tried to place it directly under META-INF too, still did not work.

             

            Sorry it was a typo, please see persistence.xml as below:

             

            <xml version="1.0" encoding="UTF-8"?>

            <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://java.sun.com/xml/ns/persistence  http://java.sun.com/xml/ns/persistence/persistence_2.0.xsd">

            <persistence-unit name="war_PU" transaction-type="JTA">

            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

            <jta-data-source>java:/jdbc/mydb</jta-data-source>

            <class>my.package.entities.ClassA</class>

            <exclude-unlisted-classes>false</exclude-unlisted-classes>

            <properties>

            <property name="eclipselink.logging.level" value="INFO"/>

            </properties>

            </persistence-unit>

            </persistence>

            • 3. Re: Can't find persistence unit named in deployment
              jewellgm

              Is your war file embedded within an ear file?  Thanks for the directory tree, but I meant where are are those items from within your deployed application, and not the source tree.

               

              For example:

               

              app.ear

              |_ app.war

                |_ WEB-INF

                  |_ lib

                     |_ app.jar

              |_ META-INF

                 |_ persistence.xml

               

              or:

               

              app.war

                |_ WEB-INF

                  |_ lib

                     |_ app.jar

                  |_ classes

                     |_ META-INF

                         |_ persistence.xml

              • 4. Re: Can't find persistence unit named in deployment
                skorejo

                It is a war file. Please find the structure of deployment as following:

                 

                app.war

                |_ WEB-INF

                     |_ lib

                         |_ dao.jar

                              |_ META-INF

                                       |_ persistence.xml

                |_ META-INF

                • 5. Re: Can't find persistence unit named in deployment
                  jewellgm

                  I just noticed that your persistence provider is set to an eclipselink path.  Wildfly uses hibernate rather than eclipselink.  Try to change your provider to be "org.hibernate.jpa.HibernatePersistenceProvider".  Of course, that property setting the log level would no longer be valid.

                  • 6. Re: Can't find persistence unit named in deployment
                    skorejo

                    I changed that but it didnt resolve the error. I have noticed that on opening persistence.xml file no contents are displayed although the file size is of 1.6 kb.

                    • 7. Re: Can't find persistence unit named in deployment
                      mayerw01

                      Which editor do you use inspecting your xml file? it shoult be a pure text editor (like notepad) that does not do any interpretation. You could also use an hex edtor to verify the contents.

                       

                      Try to place your your datasource into the java:jboss context like:

                      <jta-data-source>java:jboss/datasources/mydb</jta-data-source>

                      • 8. Re: Can't find persistence unit named in deployment
                        skorejo

                        Thanks for suggesting that. My datasource created is java:/datasources/mydb instead which is why I used the same in persistence.xml, please confirm if it does'nt seem fine?

                        • 9. Re: Can't find persistence unit named in deployment
                          mayerw01

                          May be your persistence.xml file is corrupt. Did you try to inspect the file using an hex editor? You could also try to re create your file.