Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

How to get SessionFactory class's object with multi database

Thread view: 
Joey - 21 Feb 2006 16:10 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.