java


Hibernate persist same object, same table in multiple databases


We are in the process of migrating database from one DB to another and we can not afford downtime for the application. So we want to write the same entity during this process and once we migrate, we can remove the source. We are using hibernate for the application. Is there any way that hibernate can write the same entity in multiple schemas with same table structure ? . Also it should be transactional across these two DBs
You need to create 2 Sessions, each Session with one DB Connection, then when you save a bean you call the session.save() from both Sessions.
Example:
Foo foo = new Foo();
foo.setName('FooName');
foo.setType('FooType');
session1.save(foo);
session2.save(foo);
You can wrap it in a Service so you can treat with a #Transactional and avoid saving in one DB and not on the other.
If you are familiar with persistence unit then it will work great for you. You can work with multiple data-sources (i mean, database connections) defining persistence unit. See the documentation of spring persistence unit and persistence context.
I hope it will help you what you trying to achieve.

Related Links

What's the best way to share JARs across multiple projects?
JTabbedPane.getTabComponentAt(int) returning null
Accessing Liferay web content from inside a portlet?
How do I cleanup an opened Process in Java?
Why is Tomcat doubling my log lines in the catalina.out logfile?
What are the benefits of JCA?
How do I register a server in the default RMI registry for JBoss and access it from a client running in another JVM?
How to handle errors for a facade method that performs many disparate background changes?
Java library\application to Build SQL Frontend GUI's
How Can I create more than 14000 clients using HTTP (Tomcat) while HTTP works over TCP hence socket is created
Java Applet starts up very slowly for some users?
How to embed java application into a jsp page
Java: Traversed Tree to Tree
Classpath validation in ant
Configure two version of same jar in single application
Ignoring your own UDP broadcasts in Java

Categories

HOME
log4j
osgi
gremlin
reserved
stock
session
dot
spagobi
jgroups
ip
win32gui
fingerprint
directx
multiple-records
cross-validation
elasticsearch-hadoop
vifm
u-sql
etl
clearcase-ucm
workload-scheduler
propel
openedx
firefox-webextensions
introduction
css-animations
wkwebview
dcevm
smb
wpfdatagrid
fifo
saas
librato
junit5
pim
restlet
space-complexity
serverside-rendering
abstract-class
xenforo
document.write
azure-ml
cookiecutter-django
texmaker
unixodbc
osx-mavericks
worksheet
crypt
linode
dwscript
minimization
angular-strap
asp.net-4.5
sdf
iad
pervasive-sql
r-tree
jms2
cartesian-product
retina
browser-bugs
ami
system32
kineticjs
fscommand
rake-task
camanjs
tt-news
google-style-guide
relocation
sgen
fluentautomation
jquery-layout
undefined-reference
oam
sitemesh
dataservice
gridcontrol
android-screen-support
lcs
simba
bitsharp
runas
appconkit
online-compilation
wse3.0
nsdatecomponents
doh
joyent
hamachi
android-sdk-2.1
lpeg
yslow
fluent-interface
dentrix
uimenucontroller
privilege
anti-piracy
dbisam
ugc

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App