• 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 ]
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!