I have several small java projects that access to same DB. Is it possible to have one persistence.xml file, which is somewhere on the file system (not included in any jars, wars, ears, etc.) and it is still visible to the projects? The reason is that there is a requirement that the persistence.xml has to be easily replaceable and configurable and the configuration has to be done on one place for all projects.
Asked
Active
Viewed 614 times
2
-
why don't you extract the persistence functionality in a separate project on which all others depend? – Olimpiu POP Jan 07 '14 at 14:19
-
Each of the projects use the DB in specific way and it does not make sense to us to have the persistence functionality separately from the projects. Even if there were a separate project with persistence functionality, it would not solve the problem to have a persistence.xml outside of zip, jar, war etc. – Paprika Rika Jan 07 '14 at 14:45
1 Answers
0
Sounds like a question somewhat similar to this: Package a runnable JPA jar putting persistence.xml outside
The answer appears to be no. However, if you were using Spring to bootstrap the persistence manager, you could wire the datasource independent of the persistence.xml and have the properties loaded from a centralized .properties file. Look at this answer for more ideas: loading .properties in spring-context.xml and persistence.xml

Community
- 1
- 1

Shawn Sherwood
- 1,968
- 2
- 19
- 30
-
Well, it really looks like there is no way to make it without any hacks. It is interesting that JPA does not allow such a thing. For the production this is really annoying issue. Anyway, thanks for the answer. – Paprika Rika Jan 07 '14 at 14:54