views:

43

answers:

1

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.

A: 

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.
Pascal Thivent
you mean deploy only the client and undeploy the server?
Vashishtha Jogi
@Vashishtha No, I mean deploying the client and the server but only once the update of the schema is done.
Pascal Thivent
@Pascal I am doing the exact same thing. But its not working :(
Vashishtha Jogi
@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 Thivent
@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.
Vashishtha Jogi
@Vashishtha Well, I have no idea why the server gets undeployed. Actually, I'm not sure to understand the full architecture, what components are involved, etc. IMHO, you should clarify your question, add the details you mentioned in comments. Then maybe someone will be able to come with an explanation.
Pascal Thivent