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.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath*:test/merlin-persistence.xml"/>
<!-- <property name="persistenceUnitManager" ref="persistenceUnitManager"/> -->
<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.auto" value="update" />
</map>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
</property>
</bean>

<!-- Define the EntityManagerFactory -->
<bean id="geoentityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!-- <property name="persistenceUnitManager" ref="geopersistenceUnitManager"/> -->
<property name="persistenceXmlLocation" value="classpath*:test1/geolocate-persistence.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.auto" value="update" />
</map>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
</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
pkseepathiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pkseepathiAuthor Commented:
when i tried to run localling using main method in java and tried to call applicationcontext tables are generated perfectly in two databases, but when i tried to run the same in tomcat, the tables are mixed in both databses, am i doing anything wrong or do i have to set anything on tomcat server please suggest
0
Sathish David Kumar NArchitectCommented:
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
0
rajkumar_pbCommented:
Add these lines in web.xml

      <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext-hibernate.xml,/WEB-INF/applicationContext-hibernate2.xml</param-value>
      </context-param>
      
      <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-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
0
Sathish David Kumar NArchitectCommented:
sorry i wrongly mention the name .... rajkumar is correct

contextConfigLocation  only .... instances of ServletContextLoader
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pkseepathiAuthor Commented:
not a desirable solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.