-->
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.  [ 4 posts ] 
Author Message
 Post subject: Object graph on several databases
PostPosted: Fri Feb 13, 2004 9:52 am 
Newbie

Joined: Mon Sep 08, 2003 3:04 pm
Posts: 12
Hi,

I actually use Hibernate 1.2.5
The data I have to exploit in hibernate powered applications are set on several databases.
eg (with manytoone associations):

GrantClass ===>user===> UserClass
ReportClass ===>user===>UserClass

GrantClass is mapped on tbl_grants on database A
UserClass is mapped on tbl_users on database A
ReportClass is mapped on tbl_reports on database B

Actually, to solve this kind of graph I declare 2 JNDI session factories.

In Session Factory A, GrantClass and UserClass are joined by many-to-one and one-to-many hibernate properties ==> Very useful.
In Session Factory B, I declare a "long" property on the ReportClass mapping to join with the tbl_users table ==> not useful at all.

So an example of code exploiting these classes is :

Session sA = sfA.openSession();
Session sB = sfB.openSession();

UserClass u = (User)sA.load(UserClass.class, new Long(1234));
u.initialize(sB);
//in UserClass : public void initialize(Session s) {
// set reports = s.find("from r in class ReportClass where r.userId = "+this.getKey())
//



Is there a smarter way to build objects graphs with data on several datasources. I didn't find such a solution in Hibernate 1.2.x. Does Hibernate 2.x does it ?

For example, I would like to declare in some manner in User mapping a one-to-many java Set using an other session.

Sorry if it isn't very clear (my english isn't fluent !)

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 9:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No Hibernate does not do mapping over mutliple databases, not in 2.1.2 too.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 9:59 am 
Regular
Regular

Joined: Tue Aug 26, 2003 3:09 pm
Posts: 58
IIRC, there was some mention in the past about writing a custom UserType to do it. I don't know the details though - I have never tried it.

Also, what database are you using? Some databases allow cross db joins, which would allow you to map all classes in a single SessionFactory by using the schema attribute of the class mapping (I do this in SQL Server 2000, for example).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 10:09 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Note that a solution at the database level is much better. Most DBMW have some kind of database links, so this is only an issue in a heterogenous setup.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.