Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add support for several Hibernate bundles #1276
In some cases one need to simultaneously connect to several relational databases. Users want to use Hibernate to access each database. The problem that the current implementation of
Another problem is that users should have the ability to specify the name of datasource, against which a transaction should be opened in a resource method.
In the result users can simultaneously use declarative transactions on several databases, access to which is managed by Hibernate.
added a commit
this pull request
Oct 12, 2015
This is great, I have been looking to be able to do this for a while. Just one question - is it possible to use two different session factories within a single resource method? I have a number of resources that need to be able to access user settings from one database and information from a different one. I would have thought that this would be possible since each of the DAOs takes in their relevant bundle that they will use.
referenced this pull request
Nov 25, 2015
This totally breaks if you need to use both databases within one resource call by having the UnitOfWork value coupled directly with the bundle name. My use case is such that I need to update a legacy database with a bit of data, but also create an entry within my new database within a POST. However, since the transaction has to be tied to one, and only one, bundle (even if I set 'transactional' to false), then I only have context into one of my databases, making it impossible to solve my use case
It's awesome that Dropwizard hibernate supports multiple hibernate bundle.
Suggest If I am missing anything.
Configuration.class has DB related configs.
Yes, It is correct that
You could work this around by splitting your resource method into several parts, each of them talks to a different database. Then annotate each of these parts (functions or services) with @unitofwork(value = 'needed-db'). And remove the top UnitOfWork annotation from the resource method.
it could be something like this: