Hi,
in a book about RCP I found and use follwing:
private EntityManager getEntityManager() {
ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader( new
SupplementalClassLoader(contextClassLoader));
entityManagerFactory =
Persistence.createEntityManagerFactory(
"fita-EmbeddedDriver", loadParameter());
entityManager =
entityManagerFactory.createEntityManager();
} catch (Exception e) {
getLog().log(new Status(IStatus.ERROR, PLUGIN_ID,
e.getMessage()));
getLog().log(new Status(IStatus.ERROR, PLUGIN_ID,
"openJPA not connected, using XML
PersistanceManager!"));
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
return entityManager;
}
and
private class SupplementalClassLoader extends ClassLoader {
private SupplementalClassLoader(ClassLoader parent) {
super(parent);
}
@Override
public Enumeration<URL> getResources(String name) throws
IOException {
final URL[] entries =
FileLocator.findEntries(getBundle(), new Path(name));
if (entries.length > 0) {
return new Enumeration<URL>() {
private int i = 0;
public boolean hasMoreElements() {
return i < entries.length;
}
public URL nextElement() {
try {
return
FileLocator.resolve(entries[i++]);
} catch (IOException e) {
return entries[i-1];
}
}
};
}
return super.getResources(name);
}
}
So the problem with return null was resolved.
Bye
Marco
> Hi,
> When I run my test as a standalone Java program, things
> work. When I launch the same code from within a plugin in
> an Eclipse RCP app, Persistence.createEntityManagerFactory
> returns null.
>
> I have called Persistence.createEntityManagerFactory both
> ways, with and without persistence.xml. Get null both
> ways.
>
> I have googled and have done everything recommended in
> those posts, including initializing the factory with
> properties and making sure the jdbc driver is on the class
> path. Still get null.
>
> I feel I am now going round in circles. Any hints?
>
> Thanks, chris
>
>
>
>