5

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

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.

1 Answer 1

3

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.
Sign up to request clarification or add additional context in comments.

6 Comments

you mean deploy only the client and undeploy the server?
@Vashishtha No, I mean deploying the client and the server but only once the update of the schema is done.
@Pascal I am doing the exact same thing. But its not working :(
@Vashishtha I'm sorry but "it's not working" doesn't say anything about the problem. Activate logging as suggested, explain what you did or changed, what the current result is.
@Pascal Sorry for being so vague. I did the following things: 1) Enabled logging 2) deployed server and then client. In the logs, I see insert statements when start the server. But when I start the client, the persistence unit of server gets undeployed and then persistence unit of client gets deployed, clearing all the data in the database.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.