I want to have my persistence.xml in conf folder of my app. How can I tell Persistence.createEntityManagerFactory that it should read it from there?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
This solution worked for me
The ClassLoader may be a URLClassLoader, so try it this way:
It should work. Works for me under certain test etc conditions. Please this is a hack and should not be used in production.
My solution is for EclipseLink 2.7.0 and Java 9 and it is modified and detailed version of @Evgeniy Dorofeev answer.
In
org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor
online 236
we see the following code:This code is used by EclipseLink to compute root url of the persistence.xml path. That's very important because final path will be made by adding
descriptorPath
topuRootUrl
.So, let's suppose we have file on
/home/Smith/program/some-folder/persistence.xml
, then we have:Details:
eclipselink.persistencexml
. If we don't do that then default descriptorPath will be equal toMETA-INF/persistence.xml
and we would need to keep our persistence.xml on/home/Smith/program/META-INF/persistence.xml
to be found.If you are using EclipseLink you can set the persistence.xml location with the persistence unit property, "eclipselink.persistencexml".
The createEntityManagerFactory methods search for persistence.xml files within the META-INF directory of any CLASSPATH element. if your CLASSPATH contains the conf directory, you could place an EntityManagerFactory definition in conf/META-INF/persistence.xml