Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DAO with Hibernate(multiple datasources)

 
jay roy
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys

I am using DAO with hibernate in my persistance layer.

but my requirment is such that inside the DAO implimentation class i want to make use of two datasources.

thi is my DAO

public class TestDaoImpl implements TestDao

{
public TestReturnVO insertInfo(TestVO testVO)
{

System.out.println("INSERT INFO INTO TABLE1 OF 'DATABASE1' using Hiberante datasource ");
return TRVO;
}


public TestReturnVO retrieveInfo(TestVO testVO)
{

System.out.println("Retrieve INFO FROM TABLE1 OF 'DATABASE2' Using Hiberante datasource");
return TRVO;
}


}

Any idea how i should go about implimenting the above scenario? Do i use abstract factory design pattern in my DAO to connect to Multiple databases?

How should i change the hibernate configuration file so that it can use two datasources instead of one?

any implimentation code would be greatly appreciated

thanks
Jay
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate works from a SessionFactory, and a SessionFactory is associated with one DataSource. If you need to use two, you need two SessionFactories. The logic of which to open a session in for a particular object will need to be done manually in your DAO.
[ June 05, 2007: Message edited by: Paul Sturrock ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic