Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Data Access

Reply
 
Thread Tools Display Modes
  #1  
Old Jun 22nd, 2006, 12:43 PM
bjneuman bjneuman is offline
Junior Member
 
Join Date: Jun 2006
Posts: 5
Default JPA Persistence.xml parse error

Apologies for the duplicate post.

Hello,
I am trying to use Spring JPA on Tomcat and can not seem to get past this error:
Code:
Jun 22, 2006 12:08:46 PM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring-persistence-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot parse persistence unit from class path resource [META-INF/persistence.xml]
Caused by: java.lang.IllegalArgumentException: Cannot parse persistence unit from class path resource [META-INF/persistence.xml]
        at org.springframework.orm.jpa.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:117)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.parsePersistenceUnitInfo(LocalContainerEntityManagerFactoryBean.java:268)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:213)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:237)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:901)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:870)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:393)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:257)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:248)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:332)
        at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
        at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1175)
        at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:368)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.io.FileNotFoundException: class path resource [persistence_1_0.xsd] cannot be resolved to URL because it does not exist
        at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:157)
        at org.springframework.orm.jpa.PersistenceUnitReader.validateResource(PersistenceUnitReader.java:281)
        at org.springframework.orm.jpa.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:108)
        ... 35 more
Here is my persistence unit (at /META-INF/persistence.xml):
Code:
<?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="em" transaction-type="RESOURCE_LOCAL">
    </persistence-unit>

</persistence>
And here is my spring configuration:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database" value="ORACLE" />
                <property name="databasePlatform" value="org.hibernate.dialect.Oracle9Dialect"/>
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
            </bean>
        </property>
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
        </property>
    </bean>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">        
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@xxx:1521:xxx" />
        <property name="username" value="xxx" />
        <property name="password" value="ixxx" />
    </bean>
    
    <bean id='lineItemDao' class='mil.afis.budget.LineItemDaoJpa'>
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>    
        
</beans>
Any help would be greatly appreciated.
Thanks!
Reply With Quote
  #2  
Old Jun 22nd, 2006, 12:55 PM
trisberg's Avatar
trisberg trisberg is offline
Senior Member
Spring Team
 
Join Date: Aug 2004
Location: Doylestown, Pennsylvania, USA
Posts: 1,021
Default

If you are deploying a war file try putting persistence.xml in /WEB-INF/classes/META-INF/ directory.
__________________
Thomas Risberg
SpringSource
http://www.springsource.com
Spring Framework Support, Training, Consulting
Reply With Quote
  #3  
Old Jun 22nd, 2006, 01:04 PM
bjneuman bjneuman is offline
Junior Member
 
Join Date: Jun 2006
Posts: 5
Default

Thanks for the response. Unfortunately, still get the same error.
Reply With Quote
  #4  
Old Jun 22nd, 2006, 01:43 PM
bjneuman bjneuman is offline
Junior Member
 
Join Date: Jun 2006
Posts: 5
Default

I hope we haven't exhausted all possible fixes. If more info is needed, I'll be happy to provide it.
Reply With Quote
  #5  
Old Jun 23rd, 2006, 03:17 AM
Wesslan Wesslan is offline
Member
 
Join Date: Mar 2006
Location: A place to call home
Posts: 76
Default

I'm getting the exact same error while using Spring 2.0-RC1 and Hibernate.
Reply With Quote
  #6  
Old Jun 23rd, 2006, 04:37 AM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,011
Default

There is a 'small' bug which is triggered by the lack of persistence_1_0.xsd in the classpath root. The reference implementation (toplink) contains the .xsd file in the jar while hibernate under org/hibernate/ejb3 package. I've added a fix in the CVS which will be included in RC2.
A quick and efficient fix for now is to place the persistence_1_0.xsd inside your classpath root (i.e. under WEB-INF/classes).
Sorry for the inconvenience.
__________________
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Reply With Quote
  #7  
Old Jun 23rd, 2006, 11:21 AM
bjneuman bjneuman is offline
Junior Member
 
Join Date: Jun 2006
Posts: 5
Default

Thanks. That did the trick. Of course now I've got a new error... any thoughts?
Code:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring-persistence-context.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: error trying to scan <jar-file>: file:/D:/afis-apps/ITATS/ITATS%20Worklow/build/web/WEB-INF/classes/
Caused by: java.lang.RuntimeException: error trying to scan <jar-file>: file:/D:/afis-apps/ITATS/ITATS%20Worklow/build/web/WEB-INF/classes/
        at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:550)
        at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:306)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:119)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:253)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:237)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:901)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:870)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:393)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:257)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:248)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:332)
        at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
        at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1175)
        at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:368)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: D:\afis-apps\ITATS\ITATS%20Worklow\build\web\WEB-INF\classes (The system cannot find the path specified)
        at org.jboss.util.file.JarArchiveBrowser.<init>(JarArchiveBrowser.java:40)
        at org.jboss.util.file.ArchiveBrowser.getBrowser(ArchiveBrowser.java:37)
        at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:541)
        ... 36 more
Caused by: java.io.FileNotFoundException: D:\afis-apps\ITATS\ITATS%20Worklow\build\web\WEB-INF\classes (The system cannot find the path specified)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:114)
        at java.util.zip.ZipFile.<init>(ZipFile.java:131)
        at org.jboss.util.file.JarArchiveBrowser.<init>(JarArchiveBrowser.java:35)
        ... 38 more
Reply With Quote
  #8  
Old Jun 24th, 2006, 06:28 AM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,011
Default

Quote:
aused by: java.lang.RuntimeException: error trying to scan <jar-file>: file:/D:/afis-apps/ITATS/ITATS%20Worklow/build/web/WEB-INF/classes/
at org.hibernate.ejb.Ejb3Configuration.scanForClasses (Ejb3Configuration.java:550)
at org.hibernate.ejb.Ejb3Configuration.createContaine rEntityManagerFactory(Ejb3Configuration.java:306)
at org.hibernate.ejb.HibernatePersistence.createConta inerEntityManagerFactory(HibernatePersistence.java :119)
at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalCon
Sorry but as you can see from the stacktrace, this is something hibernate specific.
Seems like HB is expecting a jar file but all it finds is a folder (and that's why the error).
Try deploying with a packed and unpacked archive and see if the behavior changes.
__________________
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Reply With Quote
  #9  
Old Jun 24th, 2006, 09:37 AM
trisberg's Avatar
trisberg trisberg is offline
Senior Member
Spring Team
 
Join Date: Aug 2004
Location: Doylestown, Pennsylvania, USA
Posts: 1,021
Default

Just noticed that there seems to be a space in one of the directory names - "/ITATS%20Worklow/" - wonder if that is the problem?
__________________
Thomas Risberg
SpringSource
http://www.springsource.com
Spring Framework Support, Training, Consulting
Reply With Quote
  #10  
Old Jun 28th, 2006, 03:57 AM
SKI_BUM SKI_BUM is offline
Junior Member
 
Join Date: Sep 2004
Location: Århus, Denmark
Posts: 10
Default

There's a bug in Hibernate 3's EntityManager that causes it to think that paths with spaces in them (%20) are files instead of directories.
A bug report has been filed a long time ago together with a fix, but it hasn't been included in the Hibernate codebase yet (if ever it seems).
See http://opensource.atlassian.com/proj...browse/EJB-178
__________________
/Jeppe
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:46 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.