-->
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.  [ 1 post ] 
Author Message
 Post subject: Multiple Database or Proper Mapping Help
PostPosted: Tue Nov 17, 2009 2:36 am 
Newbie

Joined: Tue Nov 17, 2009 1:50 am
Posts: 1
Hello,

I think the topic on using Multiple Database is already raised many times and I dont think anyone has got a specific solution for this, However I want to ponder few points and I need your help on this one. I am trying to simplify a bigger problem that I am facing with this simple example.

I have these two classes or Domain Object Defination:

Class: Owner
owner_id : primarykey/string
owner_name : String
owner_address : String
owner_city : String
owner_state : String
owner_country: String
owner_zip : String

Class: Vehicle
vin : primarykey/String
make: String
model : String
year : String
currentOwner : Owner

Data Model of above classes

Table: Owner_table
owner_id : primarykey
owner_name : Varchar
owner_address : Varchar
owner_city : Varchar
owner_state : Varchar
owner_country: Varchar
owner_zip : Varchar

Table: Vehicle_table
vin : primarykey/String
make: Varchar
model : Varchar
year : Varchar
owner_id: Varchar

The Constrain:
The above two tables Owner_table and Vehicle_table belongs to two different datasource, For example Owner_table belongs to DB2 database and Vehicle_table belongs to MS-SQL database.

Now as we have different datasource and therefore we will have two different datasources:
1. I cannot apply lazy loading for vehicle.getOwner()
2. I cannot hibernate-map one-to-one map between Vehicle class and Owner class...I can but it will throw me runtime exception as the owner table belong to different database.

Do you prescribe any solution for this to map objects in two different tables?

I thought of an alternative solution(Please let me know if this is a ok solution) where:
- I will add an hibernate interceptor on vehicleSession.
- Whenever onLoad message is called for Vehicle object I will fetch owner information using ownerSession and set the vehicle.setCurrentOwner()

How ever I have one issue with this solution:
- Since the Vehicle class refers to Owner class as an object and not by OwnerID.
- The issue is how I write a hibernate mapping xml where I specify the Vehicle class and also load the Owner class and only mapping the owner id...
- As in interceptor.onLoad method I will get Vehicle class but to load a particular owner associated with the Vehicle I need the owner id.

<hibernate-mapping>

<class name="Vehicle" table="Vehicle_table">

<id name="vin" type="<String>" column="VIN" >
...
</id>

<property name="make" type="<String>" column="make" />
....
<!-- And for the current owner I would need something like this--><property name="currentOwner->owner_id" type="String" column="owner_id" />

</class>

</hibernate-mapping>


So that inside
interceptor - onLoad(Object arg0,...) method
{
I can do the following
Vehicle vehicle = (Vehicle) arg0;
String ownerid = vehicle.getCurrentOwner().getOwner_ID();
Owner owner = ownersession.load(..ownerid...);

vehicle.setCurrentOwner(owner);
return vehicle

}


If you understood my problem kindly help me on this or if you have any question I can elaborate more...


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

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.