persistence@glassfish.java.net

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

From: Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>
Date: Fri, 09 Feb 2007 22:45:20 +0530

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-->