Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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.
 
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!