michael wrote:
Just a comment: You can not use one SessionFactory to access two databases at the same time. You have two use two, each with its own configuration/mappings. You can also not maintain object associations across databases.
Michael,
Thank you for your reply. I previously read the documentation on requiring multiple SessionFactory objects and incorprated that into my design. I also assumed that Hibernate didn't natively support associations across databases. Would you happen to know if any work/research has been done on the topic of hetrogeneous joins/associations across multiple databases, specifically related to Hibernate (didn't catch anything on the forums before I posted this thread)?
I'm working on constructing a simple prototype of the "composition" ideas I mentioned above to see if it's a feasible idea. I wanted to verify that hibernate would correctly manage a DB2User that was composed of a User object and the DB2 specfic mappings.
Example of the concept:
Code:
public class DB2User
{
private User user = null;
...other fields here...
public void setUser(User user){
}
//not sure if this will work or not
//if not then load the user manually
public setUserId(Integer id){
this.setUser(userDAO.findUserById(id));
}
public String getFirstName(){
return user.getFirstName();
}
public void preformDB2SpecificOp(){
//do something that'll affect the DB2 tables
}
...
}
then in code:
Code:
//if the autoloading wouldn't work have the db2DAO find/set the user object...
DB2User db2User = db2UserDAO.findUserById(id);
My hope is that hibernate would marshall the DB2User specific info to the DB2 tables and the User specific information to the all server "dump" tables. While it's not as "clean" in code as true inheritance, it should serve the purpose. Hopefully, I'll have the time to test that next week as it seems like a good option for this project and a "decent" way to fake cross database associations.
Your thoughts?,
Tyler