pkseepathi
asked on
hibernate multiple persistence.xmls
I have two perssitence.xmls that belongs to two databases
-----------------first persietnce.xml------------
tables --A,B,C
--------second persistence.xml----------- --------
tables X,Y,Z
I have main application-context in my service layer where I am importing above business layers xml as below:
<bean id="entityManagerFactory" class="org.springframework .orm.jpa.L ocalContai nerEntityM anagerFact oryBean">
<property name="persistenceXmlLocati on" value="classpath*:test/mer lin-persis tence.xml" />
<!-- <property name="persistenceUnitManag er" ref="persistenceUnitManage r"/> -->
<property name="persistenceUnitName" value="MerlinPU" />
<property name="dataSource" ref="dataSource"/>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.format_sql" value="true" />
<entry key="hibernate.hbm2ddl.aut o" value="update" />
</map>
</property>
<property name="jpaDialect">
<bean class="org.springframework .orm.jpa.v endor.Hibe rnateJpaDi alect"/>
</property>
</bean>
<!-- Define the EntityManagerFactory -->
<bean id="geoentityManagerFactor y" class="org.springframework .orm.jpa.L ocalContai nerEntityM anagerFact oryBean">
<!-- <property name="persistenceUnitManag er" ref="geopersistenceUnitMan ager"/> -->
<property name="persistenceXmlLocati on" value="classpath*:test1/ge olocate-pe rsistence. xml"/>
<property name="persistenceUnitName" value="GeolocatePU" />
<property name="dataSource" ref="geodataSource"/>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.format_sql" value="false" />
<entry key="hibernate.hbm2ddl.aut o" value="update" />
</map>
</property>
<property name="jpaDialect">
<bean class="org.springframework .orm.jpa.v endor.Hibe rnateJpaDi alect"/>
</property>
</bean>
but when i start my tomcat server ,
two databses have all the tables A,B,C,X,Y,Z ..how can i generate databses only with respeective tables, am i doing anything wrong
-----------------first persietnce.xml------------
tables --A,B,C
--------second persistence.xml-----------
tables X,Y,Z
I have main application-context in my service layer where I am importing above business layers xml as below:
<bean id="entityManagerFactory" class="org.springframework
<property name="persistenceXmlLocati
<!-- <property name="persistenceUnitManag
<property name="persistenceUnitName"
<property name="dataSource" ref="dataSource"/>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.format_sql"
<entry key="hibernate.hbm2ddl.aut
</map>
</property>
<property name="jpaDialect">
<bean class="org.springframework
</property>
</bean>
<!-- Define the EntityManagerFactory -->
<bean id="geoentityManagerFactor
<!-- <property name="persistenceUnitManag
<property name="persistenceXmlLocati
<property name="persistenceUnitName"
<property name="dataSource" ref="geodataSource"/>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.format_sql"
<entry key="hibernate.hbm2ddl.aut
</map>
</property>
<property name="jpaDialect">
<bean class="org.springframework
</property>
</bean>
but when i start my tomcat server ,
two databses have all the tables A,B,C,X,Y,Z ..how can i generate databses only with respeective tables, am i doing anything wrong
use ServletContextLoader in web.xml then both the xml file will load u can use what ever bean id you need the debened upon the request itwill select the xml file 1 or 2
Add these lines in web.xml
<context-param>
<param-name>contextConfigL ocation</p aram-name>
<param-value>/WEB-INF/appl icationCon text-hiber nate.xml,/ WEB-INF/ap plicationC ontext-hib ernate2.xm l</param-v alue>
</context-param>
<listener>
<listener-class>org.spring framework. web.contex t.ContextL oaderListe ner</liste ner-class>
</listener>
Create two seperate Session Factory for two mapping files.
Call the desired one (one you want to use) in the Services. Thats it
<context-param>
<param-name>contextConfigL
<param-value>/WEB-INF/appl
</context-param>
<listener>
<listener-class>org.spring
</listener>
Create two seperate Session Factory for two mapping files.
Call the desired one (one you want to use) in the Services. Thats it
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
not a desirable solution
ASKER