Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 29609 invoked from network); 20 Jul 2009 14:19:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Jul 2009 14:19:26 -0000 Received: (qmail 37777 invoked by uid 500); 20 Jul 2009 14:20:31 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 37752 invoked by uid 500); 20 Jul 2009 14:20:31 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 37742 invoked by uid 99); 20 Jul 2009 14:20:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jul 2009 14:20:31 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [62.149.128.202] (HELO smtp1.aruba.it) (62.149.128.202) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 20 Jul 2009 14:20:22 +0000 Received: (qmail 29623 invoked by uid 89); 20 Jul 2009 14:19:55 -0000 Received: from unknown (HELO webmaildh5.aruba.it) (marco.schwarz@cioppino.net@10.10.10.94) by smtp1.aruba.it with SMTP; 20 Jul 2009 14:19:55 -0000 Received: from 195.254.224.77 by HTTP Sender: marco.schwarz@cioppino.net From: "Marco Schwarz" To: users@openjpa.apache.org Subject: re: newbie: null Entity Manager Factory in Eclipse X-Mailer: Quality Web Email v3.1s X-Originating-IP: 195.254.224.77 Date: Mon, 20 Jul 2009 16:19:56 +0200 Message-id: <4a647d0c.1b8.6104.191393130@webmaildh5.aruba.it> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: smtp1.aruba.it 1.6.2 0/1000/N X-Virus-Checked: Checked by ClamAV on apache.org 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" 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 getResources(String name) > throws IOException { > > final URL[] entries = > FileLocator.findEntries(getBundle(), new Path(name)); > > if (entries.length > 0) { > return new Enumeration() { > 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 > > > > > > > >