Multiple JPA persistence units pointing to same database?
Can we have more than one JPA persistence units pointing to same database, in different Java projects and deployed on the server at the same time? By same time I mean, not deployed at the same second but deployed together. I am using a hsqldb databas开发者_运维知识库e.
I am having a client-server model for my project. I have one single unified database table in which server fills data and then the client access that data in a different project. I can successfully populate the database through server. But when I deploy the client project all the data from the database gets erased.
I am using <property name="hibernate.hbm2ddl.auto" value="update" />
for both persistence units.
Can we have more than one JPA persistence units pointing to same database, in different Java projects and deployed on the server at the same time?
As long as you don't have incompatible mappings in both projects, this should work. You won't be able to use second level caching though.
But when I deploy the client project all the data from the database gets erased. (...)
That's not really the behavior I'd expect with hbm2ddl.auto
set to update
but I don't know if the behavior is well defined when used in a "cluster-like" environment (with several JVMs performing an update in the same time).
What happens when you deploy the client once the server part is done initializing?
My advices:
- Setup logging to see what is happening exactly
- If you are sharing the same entities, maybe don't
update
on the client and the server (although this shouldn't be a problem if done one after the other). - Ultimately, don't use
update
at all on production database.
精彩评论