Hi everybody.
In my code. I need to connect multi databases at same time. I readed
Hibernate manual. for only one db. I need to create a Hibernate.cfg.xml
and a class to get a SessionFactory type object.
but for multi database. I think the most simple way is like this.
define hibernate config file for every database. and then modify the
HibernateSessionUtil class:
public class HibernateSessionUtil {
private static SessionFactory sessionFactory1;
private static SessionFactory sessionFactory2;
private static SessionFactory sessionFactory3;
public static Session currentSession(String fileName)
throws HibernateException {
if (filename == "filename1" ) {create sessionFactory1};
else if (filename == "filename2" ) {create sessionFactory2};
else if (filename == "filename3" ) {create sessionFactory3};
else return null;
}
}
but I don't think it is a good way. because it is not ugly.
who can give me some ideas make those code flexible and clean.
Thanks
Joey
Joey - 21 Feb 2006 17:08 GMT
sorry. a mistake.
/but I don't think it is a good way. because it is not ugly.
/who can give me some ideas make those code flexible and clean.
should be
but I don't think it is a good way. because it is ugly .
who can give me some ideas make those code flexible and clean.
And I think it's no a question about Hibernate , it's a design pattern
question. I try to solve it by factory method or simple factory....
but because the method and properties in this Class are Static. So no
idea how to do it.
Joey.