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

Implement a 4g toggle for android (private only)
JList content not updated
How can I get a List<String> of the keys from a HashMap<String, String>?
Adjust image's contrast
ClassCastException Beansbinding Java
Organizing members of a class java [closed]
Jars in eclipse dependant project's Web app libraries not being exported
Xmldsig signature on SOAP message
Alternate to #XmlRootElement?
Creating Hang man game [closed]
Android portrait locked Camera Preview
Creating own checked exceptions
How to call a cached xsl template from different class than init()
Caused by: java.awt.print.PrinterException: No print service found. Windows Server 2008 - Java
Java code for reloading jqgrid
AndEngine crashes on users phone but not development phone

Categories

HOME
jdo
gitlab
comparison
session
ip
ckeditor
fingerprint
yum
basic
communication
postgres-xl
google-apps-marketplace
commonmark
messages
workload-scheduler
systemc
ef-migrations
riot.js
orleans
devops
claims-based-identity
lcd
chromebook
react-css-modules
bootstrap-material-design
tooltipster
fabric8
media-queries
iframe-resizer
stringtemplate
google-api-nodejs-client
picasso
nssegmentedcontrol
x11-forwarding
sqlite2
email-templates
ensembles
galen
reportingservices-2005
mime
outlook-api
http-redirect
galleria
scorm
parentheses
react-scripts
fancybox-2
git-diff
spring-cache
crosswalk-runtime
static-ip-address
google-feed-api
azure-sdk
merge-conflict-resolution
nsviewcontroller
maven-tomcat-plugin
reactive-banana
msys
retina
iis-arr
quicklisp
android-listview
appfabric-cache
mono-embedding
sonarqube5.1.2
npapi
geonetwork
nsmutabledictionary
modalpopup
offloading
winddk
qcodo
nsbutton
id3v2
code-access-security
article
starcluster
uitouch
jquery-layout
meteor-velocity
quantlib-swig
dexterity
tws
sabredav
subscript
external-accessory
lpeg
fluent-interface
bespin
libs
mtj
xetex
post-build
wsdl.exe
signal-handling

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