Announcement Announcement Module
Collapse
No announcement yet.
Override Datasource definition in LocalContainerEntityManagerFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Override Datasource definition in LocalContainerEntityManagerFactoryBean

    i am not able to override the datasource that was in persistence.xml with LocalContainerEntityManagerFactoryBean.
    How can I re-use same persistence.xml file for test and JEE deployments? Do we need to maintain multiple copies of persistence.xml?

    persistence.xml (for both test and server deployments)

    Code:
    <persistence version="2.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_2_0.xsd">
    	<persistence-unit name="Jpa-SpringData">
    		<jta-data-source>DS_TEST</jta-data-source>
                    <class>entity.Employee</class>
    	</persistence-unit>
    </persistence>
    applicationContext.xml for JUnit testing:
    Code:
            <bean id="testDS" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    		p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}"
    		p:password="${jdbc.password}" />
    	
    	  <bean id="entityManagerFactory"     class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="testDS" />
                <property name="persistenceUnitName" value="Jpa-SpringData" />
                <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
                    <property name="showSql" value="true" />
                    <property name="generateDdl" value="false" />
                    <property name="database" value="ORACLE" />
                </bean>
            </property>
        </bean>
    Any help is appreciated.

    Thanks
Working...
X