hibernate entitymanager

I have two database instances, with different table structure, i defined two entitymanagers, two entitymanagerfactories as below
----------------------FIRST SPRING-CONTEXT.XML -----------------------------
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
            <property name="persistenceXmlLocations">
                  <list>
                        <value>classpath*:META-INF/persistence.xml</value>
                  </list>
            </property>
            <property name="defaultDataSource" ref="dataSource"/>
      </bean>

      <!-- Define the EntityManagerFactory -->
      <bean id="entityManagerFactory"      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="persistenceUnitManager" ref="persistenceUnitManager"/>
            <property name="persistenceUnitName" value="PU" />
            <property name="dataSource" ref="dataSource"/>            
            <property name="jpaVendorAdapter">
                  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                        <property name="database" value="MYSQL" />
                        <property name="showSql" value="__MERLIN_JPA_SHOW_SQL__" />
                        <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                  </bean>
            </property>
            <property name="jpaPropertyMap">
                  <map>
                        <entry key="hibernate.format_sql" value="true" />
                        <entry key="hibernate.hbm2ddl.auto" value="create" />
                  </map>
            </property>
            <property name="jpaDialect">
                  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
            </property>
      </bean>
      
      <!-- Define an EntityManager -->
      <bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
            <property name="entityManagerFactory" ref="entityManagerFactory"/>
      </bean>

----------------------SECOND SPRING-CONTEXT.XML -----------------------------
<bean id="geopersistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
            <property name="persistenceXmlLocations">
                  <list>
                        <value>classpath*:META-INF/geolocate-persistence.xml</value>
                  </list>
            </property>
            <property name="defaultDataSource" ref="geodataSource"/>
      </bean>

      <!-- Define the EntityManagerFactory -->
      <bean id="geoentityManagerFactory"      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="persistenceUnitManager" ref="geopersistenceUnitManager"/>
            <property name="persistenceUnitName" value="GeoPU" />
            <property name="dataSource" ref="geodataSource"/>            
            <property name="jpaVendorAdapter">
                  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                        <property name="database" value="MYSQL" />
                        <property name="showSql" value="__JPA_SHOW_SQL__" />
                        <property name="databasePlatform" value="merlin.geo.persistence.CustomHSQLDialect" />
                  </bean>
            </property>
            <property name="jpaPropertyMap">
                  <map>
                        <entry key="hibernate.format_sql" value="__JPA_FORMAT_SQL__" />
                        <entry key="hibernate.hbm2ddl.auto" value="create" />
                  </map>
            </property>
            <property name="jpaDialect">
                  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
            </property>
      </bean>
      
      <!-- Define an EntityManager -->
      <bean id="geoentityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
            <property name="entityManagerFactory" ref="geoentityManagerFactory"/>
      </bean>

aind importing above spring xmls into my main service layer xml like below

----------------------MAIN SPRING-CONTEXT.XML -----------------------------
<import resource="classpath*:business-spring-context.xml"/>
      <import resource="classpath*:geolocate-business-spring-context.xml"/>

when i ma doing this and creating databse through spring, two databases are crated with same tables in both databses with persistence.xmls mixed,
for ex: if firstpersistence.xml has table A,B
and second spring-persistence.xml has table X,Y
resulting databases contains tables A,B,X,Y

please advise a solution

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

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 got a desirable solution
0
Sathish David Kumar NArchitectCommented:
@pkseepathi:

Thanks for your point ...

But your not come for futher more dicuession then only we dont konw you are getting corecct answer or not ??

Here after if u post a question you also pariticipate in that questiion then only we will know that !!
Thanks ...
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.