• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Connecting to two schemas using hibernate

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to hibernate and Struts �. My application use spring , struts and hibernate mapping.

The requirement is to create a new schema and to fetch the data from both the schemas �.. I need to take data from both the schemas�. Both the schemas are having the same set of tables (Table names are same across the schemas)

In my dataAccessContext-jta.xml , datasource is defined as follows�.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc racle:thin:@someserver</value>
</property>
<property name="username">
<value>usrname</value>
</property>
<property name="password">
<value>passwd/value>
</property>
</bean>


My question is whether its possible to connect to two different schema s using hibernate � If so how can we go about it� Please help me in this�

Thanks
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is, however you will need a SessionFactory per DataSource to do it. You can create a SessionFactory that spans more than one DataSource.
 
Hamsa Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply,

Could you please explain how to do this .... As I am new to Spring and hibernate could you please explain the steps...

Thanks,
[ June 23, 2008: Message edited by: Hamsa Kumar ]
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate's documentation covers configuration. This is a good place to start.
 
Hamsa Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could you please brief on the changes needs to be done. In the dataaccessContext.xml file we have dfined a data source which points to a single database. The Session factory and the transaction manager are mappedd to this data source. How can I define a new datasource and switch the mapping dynamically.



Here Hibernate transaction manager is used. Will this be ok.
Please explain .

Thanks

[ Edited to use code tags - Paul Sturrock ]
[ June 23, 2008: Message edited by: Paul Sturrock ]
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid I don't know much about Spring. Hibernate itself has a one to one mapping between a SessionFactory and a DataSource, and since Spring delegates to Hibernate I can only assume that you need more than one DataAccessContext? In a non-Sping application I would implement this in my DAO layer by switching between SessionFactories dependent on the object I was maintaining; presumably you know from the type which database it belong in? Sorry I can't be of much help how to do this in Spring.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic