Dat Nguyen
Dat Nguyen

Reputation: 232

Use same database in 2 different maven projects

Like the title of my question implies, I have 2 maven projects in my eclipse workspace : let's call them project A and B. Project B is a dependency of project A.

In project A, I have a persistence.xml file with the database properties. In project B, I will use the same database. My question is this : how do I set up the persistence.xml file ? Is it just a copy of the persistence.xml file in project A or there are some differences ?

Thank you in advance for your reply

Upvotes: 0

Views: 144

Answers (1)

Mike
Mike

Reputation: 932

persistence.xml file is used by JPA provider to provide the required configurations related to the data layer. Here, you can define one or more persistence units, which can be used to manipulate data. You can think of a persistence unit as an object containing all the configurations related to one datastore (database).

For example, you may define two persistence units, targeting two different databases:

<persistence-unit name="my-pu-1">...</persistence-unit>

and

<persistence-unit name="my-pu-2">...</persistence-unit>

To answer your question, if you want your second project to use the same database as the first one, you can copy just properties related to the database, e.g. the address of the database, its name etc.

If you want to have the same persistence unit in the second project as in the first one, you can just copy its definition. But you can, of course, copy the whole persistence.xml and have all the persistence units you have in the first project.

Upvotes: 1

Related Questions