This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I'm new to JPA and am using EclipseLink 2.3 for persistence and develop with Eclipse (Helios). I do not have Maven or Spring or anything else.
I would like to change the location of the persistence.xml file inside META-INF folder. I have searched extensively and am not able to locate a good answer. Let me explain why.
I'm not too sure about the details of how this works but here is a short description of the setup in which I work and I really cannot change or do anything about this setup.
When I deploy an application on to the server, I copy the contents of the bin of my project to a particular folder on the server. Thus anything related to a project should never start at the root and must always be inside the package making it self contained. So for e.g. if my application is project2 and my deployment folder is service, this is the following folder structure:
And since I have started using JPA, I'm faced with the problem of the META-INF folder which is at the root of the project. If I'm using JPA in more than one project I can't have the META-INF folder of the new project at the root. In essence I can't have this:
I would like to move the persistence.xml to reside within the package like:
At the very least, even if I cannot move the META-INF folder, I should be able to relocate persistence.xml away from the root of the project to inside a package of the application.
Can someone please point me in the right direction as to how to accomplish this. Your patience and time is greatly appreciated.
Normally an application is deployed as an ear, and each ear has its own meta-inf directory which is isolated form other applications through the server's usage of classloaders. So there should be no issue.
EclipseLink does support loading the persistence.xml from another place if you pass the "eclipselink.persistencexml" property in the properties Map when you access your factory. However JPA does not support this, so your have to use the EclipseLink PersistenceProvider directly, not JPA Persistence.
Thanks for the reply James. Can you also tell me what is the difference between EclipseLink PersistenceProvider and JPA Persistence?
I thought that since EclipseLink is one of the JPA implementations, I'm already using it's PersistenceProvider. Also if they are indeed different, how will this impact my code? Should I expect a lot of change in my application or just the addition to persistence.xml and all the magic happens behind the screen. BTW, I'm not using OSGi.
Joined: Oct 01, 2007
The JPA Persistence class is part of the spec, and will return any JPA provider.