-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Mapping entities from different datasources
PostPosted: Thu Apr 28, 2005 5:31 am 
Newbie

Joined: Thu Dec 09, 2004 4:26 am
Posts: 19
Location: Yorkshire, UK
Hey Ho,

Sorry if this is really easily answered but I've got my head in a spin....

I have an orders database and a legacy account database. I would like to be able to do
Code:
order.getAccount()
and
Code:
account.getOrders()

but because they are on different databases, I get the error
Quote:
org.hibernate.MappingException: An association from the table Orders refers to an unmapped class: omnieng.burnbaby.beans.Account


Spring creates two manager objects, one for each database, but which ever is initialised first complains. I've been trying to find a way to reference an entity in a different session/database/factory but with no success.

I'm sure it's simple but I've been looking at it too long now!

Thanks for any help,
Tim

Hibernate version: 3

Mapping documents:
spring.xml
Code:
<beans>
      <bean id="accountDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
          <value>jdbc/accountDS</value>
        </property>
      </bean>
   
      <bean id="orderDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
          <value>jdbc/orderDS</value>
        </property>
      </bean>   
   <bean id="accountSessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="configLocation">
            <value>account.hibernate.cfg.xml</value>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">
               org.hibernate.dialect.Oracle9Dialect
            </prop>
         </props>
      </property>
      <property name="dataSource">
         <ref bean="accountDataSource" />
      </property>
   </bean>
   <bean id="orderSessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="configLocation">
            <value>order.hibernate.cfg.xml</value>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">
               org.hibernate.dialect.Oracle9Dialect
            </prop>
            <!-- prop key="hibernate.cache.provider_class">
               net.sf.ehcache.hibernate.Provider
            </prop-->
         </props>
      </property>
      <property name="dataSource">
         <ref bean="orderDataSource" />
      </property>
   </bean>
   <bean id="orderManager"
      class="omnieng.burnbaby.beans.OrderManager">
      <property name="sessionFactory">
         <ref bean="orderSessionFactory" />
      </property>
   </bean>
   <bean id="accountManager"
      class="omnieng.burnbaby.beans.AccountManager">
      <property name="sessionFactory">
         <ref bean="accountSessionFactory" />
      </property>
   </bean>
</beans>

hibernate configuration for Accounts
Code:
<hibernate-configuration>
   <session-factory>

      <property name="hibernate.cache.provider_class">
         org.hibernate.cache.EhCacheProvider
      </property>

      <mapping resource="omnieng/burnbaby/beans/Account.xml" />
      <mapping resource="omnieng/burnbaby/beans/Company.xml" />
      <mapping resource="omnieng/burnbaby/beans/Privilege.xml" />
   </session-factory>
</hibernate-configuration>

hibernate configuration for Orders
Code:
<hibernate-configuration>
   <session-factory>

      <property name="hibernate.cache.provider_class">
         org.hibernate.cache.EhCacheProvider
      </property>

      <mapping resource="omnieng/burnbaby/beans/Order.xml" />
      <mapping resource="omnieng/burnbaby/beans/Clip.xml" />
   </session-factory>
</hibernate-configuration>

Account configuration
Code:
<hibernate-mapping default-lazy="false">
   <class name="omnieng.burnbaby.beans.Account" table="ACCOUNT">
      <cache usage="read-write" />
      <id name="email" column="email" type="string">
         <generator class="assigned" />
      </id>
      <property name="firstName" column="first_name" />
      <property name="surname" />
      <property name="tel" />
      <property name="password" />
      <many-to-one name="company"
         class="omnieng.burnbaby.beans.Company" not-null="true">
         <column name="company_id" />
      </many-to-one>
      <bag name="orders" inverse="true" cascade="all-delete-orphan">
         <cache usage="read-write" />
         <key>
            <column name="account_email" />
         </key>
         <one-to-many class="omnieng.burnbaby.beans.Order"/>
      </bag>
      <bag name="privileges" table="ACCOUNT_PRIVILEGE">
         <cache usage="read-write" />
         <key column="account_email" />
         <many-to-many class="omnieng.burnbaby.beans.Privilege" column="privilege_id"/>
      </bag>
   </class>
   <query name="allAccounts">
      <![CDATA[from Account a order by a.email]]>
   </query>
</hibernate-mapping>

Order configuration
Code:
<hibernate-mapping default-lazy="false">
   <class name="omnieng.burnbaby.beans.Order" table="ORDERS" >
      <cache usage="read-write" />
      <id name="id" column="id" type="long">
         <generator class="increment" />
      </id>
      <property name="created" type="timestamp" />
      <property name="status"/>
      <property name="notes" column="notes" />
      <property name="projectCode" column="project_code" />
      <bag name="clips" inverse="true" cascade="all-delete-orphan">
         <cache usage="read-write" />
         <key>
            <column name="order_id" />
         </key>
         <one-to-many class="omnieng.burnbaby.beans.Clip"/>
      </bag>
      <many-to-one name="account"
         class="omnieng.burnbaby.beans.Account" not-null="true">
         <column name="account_email" />
      </many-to-one>
   </class>
</hibernate-mapping>

Name and version of the database you are using:
Oracle 9i (Accounts) and Oracle 10g (Orders)[/code]


Top
 Profile  
 
 Post subject: Re: http://forum.hibernate.org/viewtopic.php?t=941717&st
PostPosted: Thu Dec 22, 2005 7:46 am 
Newbie

Joined: Thu Dec 22, 2005 7:33 am
Posts: 2
Did you find a workaround for this problem? I'm encountering the same issue setting up session factories for databases on two different hosts.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 5:38 pm 
Newbie

Joined: Thu Dec 09, 2004 4:26 am
Posts: 19
Location: Yorkshire, UK
Yep but outside of Hibernate. I created a database link between the two and a single "virtual" schema with all tables mapped as synonyms. Oracle takes care of the separation, transactions etc.

Hope that helps,
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 7:36 am 
Newbie

Joined: Thu Dec 22, 2005 7:33 am
Posts: 2
Thanks for your response Tim. I'm using MySQL so I think I can achieve the same solution using federated tables. I'd like to find a hibernate or application level solution to this though, so it doesn't complicate my configuration or tie me to a particular rdbms.

Thanks again, and Merry Christmas!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 8:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
this is not a thing hibernate is apropriate to solve. it should be done in the db layer or at least in the jdbc layer.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.