File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Change the location of persistence.xml in JPA (Eclipselink 2.3) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Change the location of persistence.xml in JPA (Eclipselink 2.3)" Watch "Change the location of persistence.xml in JPA (Eclipselink 2.3)" New topic
Author

Change the location of persistence.xml in JPA (Eclipselink 2.3)

Karthic Raghupathi
Greenhorn

Joined: Nov 23, 2009
Posts: 9

Greetings!

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.
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
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.

If you are using OSGi, then refer to EclipseLink's OSGi support.
http://wiki.eclipse.org/EclipseLink/Examples/OSGi


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Karthic Raghupathi
Greenhorn

Joined: Nov 23, 2009
Posts: 9

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.
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
The JPA Persistence class is part of the spec, and will return any JPA provider.

If you use EclipseLink PersistenceProvider directly, it will only return an EclipseLink provider. Everything else is the same, the only difference is how you create your EntityManagerFactory.
Karthic Raghupathi
Greenhorn

Joined: Nov 23, 2009
Posts: 9

Thanks for all the help James. It is much appreciated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change the location of persistence.xml in JPA (Eclipselink 2.3)