Announcement Announcement Module
Collapse
No announcement yet.
Error when Deploying Spring JPA in a runtime environment Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error when Deploying Spring JPA in a runtime environment

    Hi all,

    I am trying to deploy my application and keep getting "Invalid XML in persistence unit f
    rom class path resource [META-INF/persistence.xml]" error on deployment. Here is the relevant part of my entityManagerFactory configuration:

    Code:
    <!-- ================================================== ======================= -->
    	<!-- General -->
    	<!-- ================================================== ======================= -->
    	<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
    	<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
    	
    	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location">
    			<value>batch-oracle.properties</value>
    		</property>
    	</bean>
    	
    	<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    		<property name="persistenceXmlLocation">
    			<list>
    				<value>classpath:META-INF/persistence.xml</value>
    			</list>
    		</property>
    	</bean>
    	
    	<!-- ================================================== ======================= -->
    	<!-- DataSource -->
    	<!-- ================================================== ======================= -->
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName">
    			<value>${batch.jdbc.driver}</value>
    		</property>
    		<property name="url">
    			<value>${batch.jdbc.url}</value>
    		</property>
    		<property name="username">
    			<value>${batch.jdbc.user}</value>
    		</property>
    		<property name="password">
    			<value>${batch.jdbc.password}</value>
    		</property>
    	</bean>
    
    	<!-- ================================================== ======================= -->
    	<!-- JPA Persistence Manager Hibernate -->
    	<!-- ================================================== ======================= -->
    
    	<!-- This is the EntityManagerFactory configuration for Hibernate -->
    	<bean id="nimmsEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="persistenceUnitManager" ref="persistenceUnitManager" />
    		<property name="persistenceUnitName" value="issue-pu"/>	
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="showSql" value="true" />
               		<property name="generateDdl" value="true" />
               		<property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
    			</bean>
    		</property>
    		
    	</bean>	
    	
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="nimmsEntityManagerFactory" />
        </bean>



    here is my persistence.xml:


    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" 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">
    
    	<persistence-unit name="issue-pu" transaction-type="RESOURCE_LOCAL">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    
    		<class>mil.dfas.tsopr.nimms.db.NimmsTest</class>
    		<class>org.springframework.batch.sample.domain.football.Player</class>
    		<class>mil.dfas.tsopr.nimms.db.NimmsMat</class>
    		<exclude-unlisted-classes/>
    		<properties>
    			<!-- property name="toplink.logging.level" value="OFF"/> -->
    			<!-- property name="toplink.logging.timestamp" value="false"/> -->
    			<!-- property name="toplink.logging.thread" value="false"/> -->
    			<!-- property name="toplink.logging.session" value="false"/> -->
    			<!-- property name="toplink.throw.orm.exceptions" value="true"/> -->
    	
    			<!-- property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/> -->
    			<!-- property name="hibernate.hbm2ddl.auto" value="create-drop"/> -->
                <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" />
                <property name="hibernate.connection.url" value="jdbc:oracle:thin:myboxexample" />
                <property name="hibernate.connection.username" value="user" />
                <property name="hibernate.connection.password" value="pass" />
                <property name="hibernate.connection.show_sql" value="true" />
                <property name="hibernate.connection.type" value="DEBUG" />
            	<property name="dialect" value="org.hibernate.dialect.Oracle10gDialect" />
    			<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
    			<property name="hibernate.archive.autodetection" value="class"/>
    		</properties>
    	</persistence-unit>
    </persistence>
    here is the error message I am getting:

    Code:
    14:02:55,751 ERROR main CommandLineJobRunner:119 - Job Terminated in error:
    org.springframework.beans.factory.BeanCreationException: Error creating bean wit
    h name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostPr
    ocessor#0' defined in class path resource [simple-job-launcher-context.xml]: Ini
    tialization of bean failed; nested exception is org.springframework.beans.factor
    y.BeanCreationException: Error creating bean with name 'nimmsEntityManagerFactor
    y' defined in class path resource [simple-job-launcher-context.xml]: Cannot reso
    lve reference to bean 'persistenceUnitManager' while setting bean property 'pers
    istenceUnitManager'; nested exception is org.springframework.beans.factory.BeanC
    reationException: Error creating bean with name 'persistenceUnitManager' defined
     in class path resource [simple-job-launcher-context.xml]: Invocation of init me
    thod failed; nested exception is java.lang.IllegalArgumentException: Invalid XML
     in persistence unit from class path resource [META-INF/persistence.xml]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory$1.run(AbstractAutowireCapableBeanFactory.java:409)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory.createBean(AbstractAutowireCapableBeanFactory.java:380)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
    ject(AbstractBeanFactory.java:264)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
    y.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
    an(AbstractBeanFactory.java:261)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
    (AbstractBeanFactory.java:185)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
    (AbstractBeanFactory.java:164)
            at org.springframework.context.support.AbstractApplicationContext.getBea
    n(AbstractApplicationContext.java:880)
            at org.springframework.context.support.AbstractApplicationContext.regist
    erBeanPostProcessors(AbstractApplicationContext.java:596)
            at org.springframework.context.support.AbstractApplicationContext.refres
    h(AbstractApplicationContext.java:365)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<i
    nit>(ClassPathXmlApplicationContext.java:139)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<i
    nit>(ClassPathXmlApplicationContext.java:83)
            at org.springframework.batch.core.launch.support.CommandLineJobRunner.st
    art(CommandLineJobRunner.java:190)
            at org.springframework.batch.core.launch.support.CommandLineJobRunner.ma
    in(CommandLineJobRunner.java:254)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
    ng bean with name 'nimmsEntityManagerFactory' defined in class path resource [si
    mple-job-launcher-context.xml]: Cannot resolve reference to bean 'persistenceUni
    tManager' while setting bean property 'persistenceUnitManager'; nested exception
     is org.springframework.beans.factory.BeanCreationException: Error creating bean
     with name 'persistenceUnitManager' defined in class path resource [simple-job-l
    auncher-context.xml]: Invocation of init method failed; nested exception is java
    .lang.IllegalArgumentException: Invalid XML in persistence unit from class path 
    resource [META-INF/persistence.xml]
    any help will be appreciated


    Regards,


    Steven Headley

  • #2
    First off all start by removing all the duplicate stuff.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" 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">
    
    	<persistence-unit name="issue-pu" transaction-type="RESOURCE_LOCAL">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    
    		<class>mil.dfas.tsopr.nimms.db.NimmsTest</class>
    		<class>org.springframework.batch.sample.domain.football.Player</class>
    		<class>mil.dfas.tsopr.nimms.db.NimmsMat</class>
    		<exclude-unlisted-classes/>
    		<properties>
    			<!-- property name="toplink.logging.level" value="OFF"/> -->
    			<!-- property name="toplink.logging.timestamp" value="false"/> -->
    			<!-- property name="toplink.logging.thread" value="false"/> -->
    			<!-- property name="toplink.logging.session" value="false"/> -->
    			<!-- property name="toplink.throw.orm.exceptions" value="true"/> -->
    	
    			<!-- property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/> -->
    			<!-- property name="hibernate.hbm2ddl.auto" value="create-drop"/> -->
                <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" />
                <property name="hibernate.connection.url" value="jdbc:oracle:thin:myboxexample" />
                <property name="hibernate.connection.username" value="user" />
                <property name="hibernate.connection.password" value="pass" />
                <property name="hibernate.connection.show_sql" value="true" />
                <property name="hibernate.connection.type" value="DEBUG" />
            	<property name="dialect" value="org.hibernate.dialect.Oracle10gDialect" />
    			<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
    			<property name="hibernate.archive.autodetection" value="class"/>
    		</properties>
    	</persistence-unit>
    </persistence>
    The stuff in red you don't need it, the stuff in blue is useless because you override those in your application context.

    In your configuration you don't need to the bean named 'persistenceUnitManager' because it is the default which doesn't need configuring.

    After doing that, try again and please post full stacktrace. You could also try moving everything to the spring configuration and create an almost empty persistence.xml file.

    Comment

    Working...
    X