-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hiding the Plumbing
PostPosted: Mon Jan 19, 2004 7:58 pm 
Newbie

Joined: Mon Jan 19, 2004 7:44 pm
Posts: 7
I am building an application which will need to present a homogenous view of data from disparate datasources. In other words, I have about seven different databases that each have similiar table structure. The key being similiar as they are not all alike, some tables have rows that others do not.

So, my general thought is to define a series of Interfaces and then have objects specific to each database implement that interface.

So for instance I have interface Foo. I would then create the following POJOs: Foo_DB1, Foo_DB2, Foo_DB3, Foo_DB4, Foo_DB5, Foo_DB6, Foo_DB7. I would configure the SessionFactory with the hbm.xml files for each of the 7 different foo objects. The only way that the Session would know which one it was connecting to would by the java.sql.Connection object I pass to it.

So, I have two questions.
#1. What does everyone think about that idea? (If you don't like it, I'd really like alternative ideas.)
#2. Can I run this query "from com.mypackage.Foo foo" and pick up the proper Foo_DB object?

Cheers,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 3:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This will not work that simply, if you map foo_db2 to a table which is not present in db1, this will surely not work. You will need different mapping files for every database, which you select accordingly on SessionFactory build time. In this case you can drop the whole multiple class thing and just map a Foo class, but different in every mapping file. Hibernate can not work on different databases for the same mapping file, so you have to merge the results manually I think.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 5:22 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Agreed with Michael.
If the extra columns are not used and have no constraints, the tables and columns name are the exact same, then you can use the same mapping (don't map extra columns).
Otherwise, do one mapping per concrete DB.

Your java code will be the same.

You cannot work on several DB in 1 session.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Follow Up Question
PostPosted: Tue Jan 20, 2004 6:50 pm 
Newbie

Joined: Mon Jan 19, 2004 7:44 pm
Posts: 7
Okay, I am thinking we are talking about the same thing. From my original post:
> I would configure the SessionFactory with the hbm.xml files for each of the 7 different foo objects.

Sorry, I thought I was making it clear that I was going to have 7 hbm.xml files, one per database.

Then again, perhaps I am going about this all wrong. The basic premise is that I have several different database all which will eventually map to same Hibernate object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Okay, fine. So just use one class, and map it in 7 different ways.


Top
 Profile  
 
 Post subject: Got it
PostPosted: Wed Jan 21, 2004 1:49 pm 
Newbie

Joined: Mon Jan 19, 2004 7:44 pm
Posts: 7
Thanks a lot!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.