persistence@glassfish.java.net

Re: issues using toplink-essentials v2-b35 in eclipse RCP plugin application

From: sud <to_sud_at_yahoo.com>
Date: Tue, 13 Feb 2007 18:01:20 -0800 (PST)

Thanks! This solved my issue. It is still inconvient in development to have to separate out the JPA code into a second Eclipse plugin project and have to jar it every time there is a modification in the JPA code. The issue is the persistence.xml file is not visible to the RCP application if it resides in a non-jarred state. Was wondering if anyone has been able to solve this. Thanks -sud ----- Original Message ---- From: Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo@Sun.COM> To: persistence@glassfish.dev.java.net Sent: Friday, February 9, 2007 11:15:20 AM Subject: Re: issues using toplink-essentials v2-b35 in eclipse RCP plugin application See if this thread helps: http://forums.java.net/jive/thread.jspa?messageID=98503 Sahoo sud wrote: > I've looked at bug #1502 and this issue appears to be different from > that. Besides, this one still shows up in Version 2 build 35. > > I'm successfully able to test the JPA code in my Eclipse plugin > project using TestNG tests. I've verified that the persistence.xml > file gets copied over to the bin/ directory correctly when the project > is built. When I launch the same plugin as a plugin into my existing > Eclipse RCP application from within my eclipse workbench I get the > following error message: > > javax.persistence.PersistenceException: No Persistence provider for > EntityManager named mydata > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89) > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) > > I debugged the issue to the findAllProviders() in the Persistence.java > class. > > private static void findAllProviders() throws IOException { > ClassLoader loader = > Thread.currentThread().getContextClassLoader(); > Enumeration<URL> resources = > loader.getResources("META-INF/services/" + > PersistenceProvider.class.getName()); > Set<String> names = new HashSet<String>(); > while (resources.hasMoreElements()) { > URL url = resources.nextElement(); > InputStream is = url.openStream(); > try { > names.addAll(providerNamesFromReader(new > BufferedReader(new InputStreamReader(is)))); > } finally { > is.close(); > } > } > for (String s : names) { > try{ > > providers.add((PersistenceProvider)loader.loadClass(s).newInstance()); > } catch (ClassNotFoundException exc){ > } catch (InstantiationException exc){ > } catch (IllegalAccessException exc){ > } > } > } > > > The problem was in the JavaSECMPInitializer.java class which is > getting called in the providers,add() method as shown above. The > emSetupImpls object in JavaSECMPInitializer.java is null. The > callPredeploy method (which I believe is responsible to populate this > object) in this class is not being called at any point during my code > execution. So I added the following vmargs to my application launch > configuration: > > -javaagent:D:\java\workspaces\RCPworkspace\reqlibs\toplink-essentials-agent.jar > > This time around I get a different error message when execution > reaches the names.addAll() method as shown above. (Notice that this > before the line where the previous error message was occuring) > > java.lang.ClassCastException: > oracle.toplink.essentials.PersistenceProvider cannot be cast to > javax.persistence.spi.PersistenceProvider > at javax.persistence.Persistence.findAllProviders(Persistence.java:112) > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79) > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) > > When I refactor the data access layer into a separate java project and > jar it add it to my plugin's dependency project all works fine. This > would work in a production setting but is not ideal in a development > environment where we have to constantly change data access code. > > At this point I'm lost and I'd appreciate any help getting this to work. > > Thanks > -sud > > > > > ------------------------------------------------------------------------ > Bored stiff? > <http://us.rd.yahoo.com/evt=49935/*http://games.yahoo.com> Loosen up... > Download and play hundreds of games for free > <http://us.rd.yahoo.com/evt=49935/*http://games.yahoo.com> on Yahoo! > Games. > > > ------------------------------------------------------------------------ > Don't pick lemons. > See all the new 2007 cars > <http://autos.yahoo.com/new_cars.html;_ylc=X3oDMTE0OGRsc3F2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDbmV3Y2Fycw--> > at Yahoo! Autos. > <http://autos.yahoo.com/new_cars.html;_ylc=X3oDMTE0OGRsc3F2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDbmV3Y2Fycw--> ____________________________________________________________________________________ TV dinner still cooling? Check out "Tonight's Picks" on Yahoo! TV. http://tv.yahoo.com/