Announcement Announcement Module
Collapse
No announcement yet.
JPA Persistence.xml parse error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #2
    If you are deploying a war file try putting persistence.xml in /WEB-INF/classes/META-INF/ directory.

    Comment


    • #3
      Thanks for the response. Unfortunately, still get the same error.

      Comment


      • #4
        I hope we haven't exhausted all possible fixes. If more info is needed, I'll be happy to provide it.

        Comment


        • #5
          I'm getting the exact same error while using Spring 2.0-RC1 and Hibernate.

          Comment


          • #6
            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.

            Comment


            • #7
              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

              Comment


              • #8
                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.

                Comment


                • #9
                  Just noticed that there seems to be a space in one of the directory names - "/ITATS%20Worklow/" - wonder if that is the problem?

                  Comment


                  • #10
                    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

                    Comment


                    • #11
                      Thanks for the heads up - knowing about bugs like that these is a time saver.

                      Comment


                      • #12
                        Thanks everyone for your help. It seems that the spaces were causing the problem.
                        This is my first use of the Spring forum and I'm impressed with the feedback. Hopefully, I'll have the chance to return the favor soon.

                        Comment


                        • #13
                          Space still causing a problem

                          Boy was I glad to find this thread :-) I've been having some problems with my spring/jpa/hibernate project and it turns out that the parent directory of my project has a space in the name. Once I renamed the parent dir everything worked. I'm using Spring 2.0.1, Hibernate core 3.2.1.ga, Hibernate EM 3.2.0.ga, and Hibernate annotations 3.2.0.ga.

                          I thought I'd post this in case someone thought the bug was fixed in Hibernate.

                          Comment


                          • #14
                            I've created a ticket for this, as the current behaviour is not guaranteed to work in all cases.

                            http://opensource.atlassian.com/proj...rowse/SPR-3748

                            Comment


                            • #15
                              Hope you guys are ok with posting this here - I have similiar issues with error trying to scan <jar-file> file://dbb.int.dexwired.net/dfs/.....

                              exception from java.io.File : URI has an authority component

                              This is coming from:

                              public File(URI uri) {

                              // Check our many preconditions
                              if (!uri.isAbsolute())
                              throw new IllegalArgumentException("URI is not absolute");
                              if (uri.isOpaque())
                              throw new IllegalArgumentException("URI is not hierarchical");
                              String scheme = uri.getScheme();
                              if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
                              throw new IllegalArgumentException("URI scheme is not \"file\"");
                              if (uri.getAuthority() != null)
                              throw new IllegalArgumentException("URI has an authority component");
                              if (uri.getFragment() != null)
                              throw new IllegalArgumentException("URI has a fragment component");
                              if (uri.getQuery() != null)
                              throw new IllegalArgumentException("URI has a query component");
                              String p = uri.getPath();
                              if (p.equals(""))
                              throw new IllegalArgumentException("URI path component is empty");

                              // Okay, now initialize
                              p = fs.fromURIPath(p);
                              if (File.separatorChar != '/')
                              p = p.replace('/', File.separatorChar);
                              this.path = fs.normalize(p);
                              this.prefixLength = fs.prefixLength(this.path);
                              }

                              So is there a problem with scanning remote directories / workaround etc - or did I miss something here?

                              Thanks for your help

                              Comment

                              Working...
                              X