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

JAXB Header security with Spring-WS
Open file with WordPad in Java
How can I cleanly map to a method that returns java.util.Optional? [duplicate]
In JaCoCos jenkins plugin How to get the graphs lines for “instructions”, “branch”, “complexity”, “method” and “class” coverage?
java.lang.ClassCastException - Log4j
Is it necessary to close jdbc connection in localhost
Rotation of RotatedRect in OpenCv
Estimating rotation angles from camera calibration of opencv
How to read notifications correctly on Android
Is there any way to call python code in android develop without installing sl4a?
snackBar type widget with two actions
Is it possible to map a texture to quads similar to OpenGL with just Graphics?
What is the difference between a Double ended linked list and a Circular linked list?
Fetch TweetTimelineListAdapter's data
How to find methods with an annotation in a class?
How to break a Aggregation,when i got expected result at camel split?

Categories

HOME
ms-access
ngrx
path-finding
layout
view
google-oauth
vault
alignment
caml
undefined
reverse-proxy
opencover
mps
language-agnostic
devops
shopware
brunch
info.plist
entitlements
fluentvalidation
objectanimator
file-rename
preg-match-all
uisplitview
karaf
scorm2004
noraui
stringtemplate
vsts-build-task
subset-sum
accelerate-framework
dynamics-crm-2013
code-search-engine
squib
gzipstream
botbuilder
http-redirect
dotcover
jedis
logparser
dandelion
svmlight
nbconvert
query-performance
gnome-shell-extensions
messenger
nested-sets
skobbler-maps
google-web-starter-kit
lttng
lib.web.mvc
sdhc
appfabric-cache
processmodel
apache-commons-net
gadt
relocation
xojo
hippomocks
mbr
centos5
ccss
inbox
blending
excel-2003
cassini-dev
rdoc
objective-c-2.0
getmessage
enter
hgsubversion
qt-jambi
locationlistener
mongomapper
mirah
vc90
microsoft-virtualization
eqatec
pascal-fc
defensive-programming
genealogy
signal-handling





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