Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Can we have multiple dataSources to single database(Can we have multiple dataSources to single database)
Can we have multiple dataSources to single database [message #1694703] Thu, 07 May 2015 09:25 Go to next message
Vijay Kumar is currently offline Vijay KumarFriend
Messages: 6
Registered: May 2013
Junior Member
I am having spring webservice application with oracle as a database. Right now i have datasource created using weblogic server. Also using eclipse linkg JPA to do both read and write transactions(insert,Read and update). Now we want to separate dataSources for read(read) and wrtie(insert or update) transactions.

My current dataSource is as followed:
URL : jdbc:oracle:thin:@localhost:1521:XE

using this i am doing both read and write transactions.

What if i do the following:
URL : jdbc:oracle:thin:@localhost:1521:XE

URL : jdbc:oracle:thin:@localhost:1521:XE

I knew that using XA datasource we can define multiple dataSources. Can i do same thing without XA dataSource. Does any one tried this kind of approch.
Re: Can we have multiple dataSources to single database [message #1694859 is a reply to message #1694703] Fri, 08 May 2015 14:12 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I am not quite sure what you are after. Outside of XA, a transaction is tied to a particular resource. That resource needs to be used for reads and writes while in the transaction scope, or there are problems - when you insert/update/delete something, that change is only visible within that transaction resource. Reads on a different datasource/connection should not be able to see those changes until the transaction commits, which will break your persistence unit.

EclipseLink and JPA does have the ability to define transactional and non-transactional datasources, so that connections from the non-transactional datasource are to be used when outside a transaction. But while in a transaction (or joined to one), JPA is required to only use the defined transactional datasource and associated connection. EclipseLink makes exceptions and has the ability to define a sequence pool to obtain shared sequence values outside of a transaction, but I don't think this is what you are referring to.

If you want two different pools to be used depending on if you are doing a 'read' transaction vs a 'write' transaction, you should define two persistence units - one for each pool - and then have the application use the appropriate one for your read/write operation.
Previous Topic:Eclipselink connection error (trying to create too many connections)
Next Topic:ConcurrentModificationException prior to updating entity.
Goto Forum:

Current Time: Fri Mar 01 12:25:09 GMT 2024

Powered by FUDForum. Page generated in 0.01766 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top