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]