0

Can I put my persistence.xml in any folder on my hard-drive and can access to it with my Java SE application?

Is there any solutions for my problem?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
George Krause
  • 59
  • 1
  • 3
  • 11
  • 2
    I prefer keeping it with the program. That ensures that they are always in sync with each other. What is the reason you want to put it somewhere else? – ppeterka Jan 07 '13 at 08:21
  • *"Is there any solutions for my problem?"* What 'problem'? – Andrew Thompson Jan 07 '13 at 08:21
  • If you really know what you are doing, you can using a datasource without persistence.xml file. The datasource file can be a simple properties file on the disk. See also http://stackoverflow.com/questions/1132565/spring-jpa-and-persistence-xml. – imxylz Jan 07 '13 at 08:44

1 Answers1

0

persistence.xml must be present under META-INF in the CLASSPATH of the running application. That is the only restriction. You could easily enough include some other location in the CLASSPATH and have your persistence.xml there as long as it was in a folder META-INF.

Some JPA providers allow you to just specify the location as a persistence property, doing away with the META-INF requirement, but then that is not covered by the JPA spec so not portable

DataNucleus
  • 15,497
  • 3
  • 32
  • 37