开发者

Multiple JPA persistence units pointing to same database?

开发者 https://www.devze.com 2023-01-19 08:13 出处:网络
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

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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号