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
|