Announcement Announcement Module
Collapse
No announcement yet.
begginers problem: persistence unit not found Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • begginers problem: persistence unit not found

    Hi all,

    i have a problem with hibernate-jpa integration with spring. I have searched the forum, but no explicit answer found for the problem

    The problem is following:

    Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'pmanager' found


    I use the simpliest configuration for jpa, that is described in spring-reference.pdf: LocalEntityManagerFactoryBean

    my applicationConfig.xml shows as

    Code:
    <bean id="entityManagerFactory"
    	class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    		<property name="persistenceUnitName" value="pmanager" />		
    </bean>
    
    <bean id="transactionManager"
    	class="org.springframework.orm.jpa.JpaTransactionManager">
    	<property name="entityManagerFactory">
    		<ref local="entityManagerFactory" />
    	</property>
    </bean>
    
    <bean id="userDAO" class="test_spring.dao.jpa.UserDAOJPA">
    	<property name="entityManagerFactory">
    		<ref local="entityManagerFactory" />
    	</property>
    </bean>
    persistence.xml have

    Code:
    <persistence-unit name="pmanager">
    		
    	<provider>org.hibernate.ejb.HibernatePersistence</provider>
    		
    	<properties>			
    		<property name="hibernate.connection.driver_class"
    			value="org.hsqldb.jdbcDriver" />
    		<property name="hibernate.connection.url"
    			value="jdbc:hsqldb:mem:appfuse" />
    		<property name="hibernate.connection.username" value="sa" />
    		<property name="hibernate.connection.password" value="" />
    		<property name="hibernate.dialect"
    			value="net.sf.hibernate.dialect.HSQLDialect" />
    		<property name="hibernate.hbm2ddl.auto" value="create" />
    			
    	</properties>
    </persistence-unit>
    both, persistence.xml and applicationConfig.xml are in META-INF and in ClassPath

    UserDAOJPA looks like
    Code:
    public class UserDAOJPA extends JpaDaoSupport implements UserDAO {
    
    	public User getUser(Long userId) {
    		return (User)getJpaTemplate().find(User.class, userId);
    	}
    
    	public List getUsers() {
    		return getJpaTemplate().find("from User");
    	}
    
    	public void removeUser(Long userId) {
    		Object user = getJpaTemplate().find(User.class, userId);
    		getJpaTemplate().remove(user);
    	}
    
    	public void saveUser(User user) {
    		getJpaTemplate().persist(user);		
    	}
    
    }
    following libraries are in ClassPath:


    antlr
    asm
    asm-attrs
    sglib
    commons-collections
    commons-logging
    commons-lang
    dom4j
    ejb3-persistence
    hibernate3
    hibernate-annotations
    hibernate-commons-annotations
    hibernate-entitymanager
    hsqldb
    jta
    log4j
    spring


    have somebody any idea, how i can solve this problem?

    many thanks and best regards,

    Nikolai
    Last edited by kumarunster; Jul 10th, 2008, 09:15 AM. Reason: solved

  • #2
    I have solved my problem:

    the META-INF-Folder was not moved into the bin-Folder (i use Eclipse IDE) if the build runs, it was only in classpath, but physicaly in root project folder...

    Regards,

    Nikolai

    Comment


    • #3
      No persistence unit with name 'jpa' found

      hello,

      I have teh same problem. I made a war that containts META-INF/persistance.xml.
      But the pb persiste.
      Any idea ?

      Thank's

      Comment


      • #4
        Hi, can you more precise/specify your problem? what do you mean with pb? Have you named your persistence unit "jpa"? How looks your Spring-Configuration?

        Comment


        • #5
          Add your WEB-INF to classpath

          If you are using eclipse
          just right click the (project) -> built path -> Configure built path

          In the source tab click Add Folder button
          add the parent folder of META-INF folder

          Comment


          • #6
            After a little research.

            The JPA *.xml files need to be locatable from the classpath*:META-INF/persistence.xml classpath*:META-INF/orm.xml however other deployment releated files need to be in the top level of the deployment unit. The use of the classpath in this way is mandated by the JPA specification.

            In the case of a regular JAR this is always the same directory.

            But in the case of a WAR it is possible to have both:

            /META-INF/MANIFEST.MF
            /WEB-INF/classes/META-INF/persistence.xml


            For me I am using Maven layouts for my projects. So a WAR project has:

            src/main/webapp/META-INF/MANIFEST.MF
            src/main/resources/META-INF/persistence.xml

            However when using the standard Eclipse WAR project layout the above two project paths would be:

            WebContent/META-INF/MANIFEST.MF
            src/META-INF/persistence.xml


            It is incorrect to add the toplevel of the website content folder to the Build Path. It is more correct to understand this difference and place the appropriate files accordingly.

            Comment


            • #7
              I believe you are correct about the maven webapp projects. While I cannot comment on which way is correct, I can share what I used to get around this problem. The way I got around this was to add the following to my pom, which pulls in the persistence.xml that's under the src/main/webapp/META-INF folder.

              <build>
              <testResources>
              <testResource>
              <directory>src/main/resources</directory>
              </testResource>
              <testResource>
              <directory>src/test/resources</directory>
              </testResource>
              <testResource>
              <directory>src/main/webapp</directory>
              </testResource>
              </testResources>
              </build>

              Originally posted by dlmiles View Post
              After a little research.

              The JPA *.xml files need to be locatable from the classpath*:META-INF/persistence.xml classpath*:META-INF/orm.xml however other deployment releated files need to be in the top level of the deployment unit. The use of the classpath in this way is mandated by the JPA specification.

              In the case of a regular JAR this is always the same directory.

              But in the case of a WAR it is possible to have both:

              /META-INF/MANIFEST.MF
              /WEB-INF/classes/META-INF/persistence.xml


              For me I am using Maven layouts for my projects. So a WAR project has:

              src/main/webapp/META-INF/MANIFEST.MF
              src/main/resources/META-INF/persistence.xml

              However when using the standard Eclipse WAR project layout the above two project paths would be:

              WebContent/META-INF/MANIFEST.MF
              src/META-INF/persistence.xml


              It is incorrect to add the toplevel of the website content folder to the Build Path. It is more correct to understand this difference and place the appropriate files accordingly.

              Comment


              • #8
                I was not asking any questions in my reply. Nor was any of the information I presented contradictory. It was simply explaining the why of the situation and providing the details necessary to place JPA files in the correct location within a project.


                I would certainly not recommend the hack to the Maven pom.xml that you suggest. This is not necessary. If you find it fixes some issue you have, then you are alleviating the symptom of another problem not effecting a cure.

                Comment


                • #9
                  Originally posted by dlmiles View Post
                  I was not asking any questions in my reply. Nor was any of the information I presented contradictory. It was simply explaining the why of the situation and providing the details necessary to place JPA files in the correct location within a project.


                  I would certainly not recommend the hack to the Maven pom.xml that you suggest. This is not necessary. If you find it fixes some issue you have, then you are alleviating the symptom of another problem not effecting a cure.
                  I agree. Sorry.

                  Comment

                  Working...
                  X