[JPA] Initializing a persistence unit with information retrieved at runtime [message #638294] |
Wed, 10 November 2010 18:01 |
Alex Mising name Messages: 149 Registered: March 2010 |
Senior Member |
|
|
Hello,
I am using EclipseLink in a JavaSE application, in which I need to initialize a persistence unit from a JAR that is loaded at runtime, but does NOT have a persistence.xml.
So, for example, suppose I have a class loader for "myentitites.jar", which does NOT include a META-INF/persistence.xml file. Suppose also that even though the persistence.xml is missing, I somehow have all the required values in a runtime Object (e.g. puInfo). How do I get from that to creating an EntityManagerFactory? I've tried:
properties.put(PersistenceUnitProperties.CLASSLOADER, myClassLoaderForAccessingTheJAR);
properties.put(PersistenceUnitProperties.SESSION_NAME, puInfo.getName());
properties.put(PersistenceUnitProperties.TARGET_DATABASE, puInfo.getDatabase());
properties.put(PersistenceUnitProperties.JDBC_DRIVER, puInfo.getDriver());
properties.put(PersistenceUnitProperties.JDBC_URL, puInfo.getURL());
properties.put(PersistenceUnitProperties.JDBC_USER, puInfo.getUser());
properties.put(PersistenceUnitProperties.JDBC_PASSWORD, puInfo.getPassword());
factory = new PersistenceProvider().createEntityManagerFactory(puInfo.getName(), properties);
However, EclipseLink returns a null object for the EntityManagerFactory without logging some error or throwing an exception...
1st edit: I use EclipseLink in an OSGi environment (using the Rich Ajax Platform).
2nd edit: I should point out that I don't care about using EclipseLink-specific APIs to achieve this. So although I would use JPA in the rest of the code, it's ok to create my EntityManagerFactory using non-standard APIs.
[Updated on: Wed, 10 November 2010 18:08] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02896 seconds