Results 1 to 9 of 9

Thread: begginers problem: persistence unit not found

Hybrid View

  1. #1
    Join Date
    Jul 2008
    Location
    Darmstadt
    Posts
    6

    Unhappy [solved] 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 at 08:15 AM. Reason: solved

  2. #2
    Join Date
    Jul 2008
    Location
    Darmstadt
    Posts
    6

    Default

    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

  3. #3
    Join Date
    Apr 2005
    Posts
    4

    Default 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

  4. #4
    Join Date
    Jul 2008
    Location
    Darmstadt
    Posts
    6

    Default

    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?

  5. #5
    Join Date
    Jan 2011
    Posts
    1

    Default 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

  6. #6
    Join Date
    Aug 2006
    Posts
    113

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •