Sorry I forgotten...

private Properties loadParameter() {

  Properties prop = new Properties();
  prop.put("openjpa.ConnectionDriverName", 
    "org.apache.derby.jdbc.EmbeddedDriver");
  prop.put("openjpa.ConnectionURL", 
   
String.format("jdbc:derby:%s\\fita.rcp\\fita.data;create=true"
, 
    System.getProperty("user.home") ));
  prop.put("openjpa.ConnectionUserName", "fita");
  prop.put("openjpa.ConnectionPassword", "fita");
  prop.put("openjpa.Log", "DefaultLevel=TRACE, SQL=TRACE");
  prop.put("openjpa.jdbc.SynchronizeMappings",
"buildSchema");
  return prop;
}

Bye Marco

----- Original Message -----
Da : "Marco Schwarz" <marco.schw...@cioppino.net>
A : users@openjpa.apache.org
Oggetto : re: newbie: null Entity Manager Factory in Eclipse
Data : Mon, 20 Jul 2009 16:16:49 +0200

> 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(contextClassL
> oader); }
> 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
> > 
> > 
> > 
> > 

Reply via email to