• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DAO with Hibernate(multiple datasources)

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic