• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
jQuery Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Karthic Raghupathi
Greenhorn
Posts: 9
jQuery Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
jQuery Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help James. It is much appreciated.
 
reply
    Bookmark Topic Watch Topic
  • New Topic