-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: any successes using entitymanager in rcp plugin?
PostPosted: Sun Sep 18, 2005 9:47 pm 
Newbie

Joined: Thu Nov 18, 2004 6:01 pm
Posts: 17
Hibernate version:
Hibernate version 3.1 beta 3, 13 September 2005
EntityManager 3.1 beta 3, 14 September 2005
Annotations 3.1 beta 5, 14 September 2005

Mapping documents:
not importanint

Code between sessionFactory.openSession() and session.close():
Failure while trying to create EntityManagerFactory.

Full stack trace of any exception that occurs:

Code:
org.hibernate.AssertionFailure: Unsupported protocol while reading jar/par: bundleresource://14
   at org.hibernate.ejb.packaging.JarVisitor.getVisitor(JarVisitor.java:86)
   at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:126)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:73)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
   at org.openaccount.utils.EntityManagerResource.getEntityManagerFactory(EntityManagerResource.aj:106)
   at org.openaccount.utils.EntityManagerResource.createEntityManager(EntityManagerResource.aj:119)
   at org.openaccount.utils.EntityManagerResource.aroundGet(EntityManagerResource.aj:58)
   at org.openaccount.ui.AccountListView$ViewContentProvider.getElements(AccountListView.java:109)
   at org.eclipse.jface.viewers.StructuredViewer.getRawChildren(StructuredViewer.java:848)
   at org.eclipse.jface.viewers.TableViewer.getRawChildren(TableViewer.java:1086)
.... more stack available....

Name and version of the database you are using:
hsqldb 1.8.0

The generated SQL (show_sql=true):
not applicable
Debug level Hibernate log excerpt:
not applicable

Just curious if anyone has success with using entitymanager in an eclipse plugin for purpose of rcp application.

I put entitymanager and annotations in a single plugin. I have a model plugin (with annotated classes) that depends on the em/anno plugin. I have a jface ui plugin which tries to get a EntityMangerFactory (through a utility class in model plugin's jar file). A view's content provider will be performing a query on the entity manager, but I don't get that far.

The first problem I had was that
Code:
META-INF/services/javax.persistence.spi.PersistenceProvider
could not be found. This is probably due to eclipse classloading scheme against the javax.persistence.Persistence context loader mechanism to find it. My workaround is to copy this file up into my ui plugin's classpath.

The second problem doesn't seem to be as easily worked around. The entitymanager wants to build a visitor for the jar file that contains the persistence.xml. But eclipse has reconstituted the url for this jar file and repalced 'jar' protocol with 'bundleresource' protocol.

Is there anyway I can get this to work or should I forget about it for now.

Thanks,
John


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 4:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The question is, how can I access this resourcebundle and read the jar file? Through a plain new File(url); some Eclipse proprietary APIs?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 12:00 pm 
Newbie

Joined: Thu Nov 18, 2004 6:01 pm
Posts: 17
(Caveat) I am by far not an expert at jar file manipulation,

But I found this bug report in eclipse platform: https://bugs.eclipse.org/bugs/show_bug.cgi?id=65673 I observed the note in the last sentence and will look for confirmation, from you and anyone else, on this proposed solution:

In all cases, JarVisitor.getJarURLFromURLEntry would use URL.URL(context, spec) constructor which will return a URL populated by defaults (protocol,...) found in context parameter. Use of this constructor allows getJarURLFromURLEntry to be protocol agnostic. If I'm wrong about that, this proposed change is crap.

ZippedJarVisitor.doProcessElements would use JarInputStream instead of JarFile and become protocol agnostic, too. JarInputStream is instantiated from the URL's openstream(). It would iterate over the ZipEntries in the JarInputStream instead of ZipEntries from the JarFile.

JarVisitor.getVisitor would instantiate ZippedJarVisitor in all protocol cases except 'file' where the file is a directory (as in the existing test).

My intent here is that the ZippedJarVisitor would be able to handle 'bundleresource' protocol. The bonus is that it should also handle 'http(s)' protocol and other unthought of protocols without further modification.

Does it have legs? I plan to try it in my limited environment to see if it works.

John


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 1:34 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Open a JIRA issue for me not to forget.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 1:46 pm 
Beginner
Beginner

Joined: Mon May 16, 2005 6:06 am
Posts: 20
As a temporary workaround you can patch the org.hibernate.ejb.Ejb3Configuration.java file as follows:

Code:
   public EntityManagerFactory createEntityManagerFactory(String emName, Map map)
   {
      try
      {
         log.debug("Trying to find persistence unit: " + emName);
         Enumeration<URL> xmls = Thread.currentThread().getContextClassLoader().getResources(
               "META-INF/persistence.xml");
         while (xmls.hasMoreElements())
         {
            URL url = xmls.nextElement();
            log.trace("Analyse of persistence.xml: " + url);

            //TODO fix starts         
            if(url.getProtocol().equals("bundleresource"))
            {
               url = org.eclipse.core.runtime.Platform.resolve(url);
            }
            //TODO fix ends   

            PersistenceMetadata metadata = PersistenceXmlLoader.deploy(url);
            JarVisitor.Filter[] filters = getFilters(metadata.getProps(), map);
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 10:15 pm 
Newbie

Joined: Thu Nov 18, 2004 6:01 pm
Posts: 17
Here is the code snippet that I wound up using because it is based on reflection and so won't impose a build time dependency for hibernate:

Code:
      if(resourceEntry.getProtocol().startsWith("bundle")) {
         try {
            Class p = Class.forName("org.eclipse.core.runtime.Platform");
            Method m = p.getMethod("resolve", URL.class);
            resourceEntry = (URL)m.invoke(null, resourceEntry);
         } catch (Exception e) {
            throw new IllegalArgumentException("Can't get bundle url.", e);
         }      
      }


PersistenceXmlLoader.deploy works fine upon the bundleresource url because eclipse provides an URLInputStream for bundleresource protocol. The difficulty is in JarVisitor.getJarURLFromURLEntry which attempts to interpret the url protocol value. So, I inserted the code above into the beginning of getJarURLFromURLEntry.

Will file a jira and reference this discussion.

Regards,
John


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 2:49 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
Will this be applied to Hibernate, or will this continue to be an external patch for (eclipse) users to apply?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 4:22 pm 
Newbie

Joined: Thu Nov 18, 2004 6:01 pm
Posts: 17
See EJB-65: http://opensource2.atlassian.com/projects/hibernate/browse/EJB-65.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 3:38 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
I have tested the hibernate entitymanager 3.1beta4, and it looks closer than it was. However, in my application code I had to do the following:

Code:
ClassLoader myclassloader = MyClass.class.getClassLoader();
  ClassLoader currentLoader = this.getClass().getClassLoader();
  try {
   Thread.currentThread().setContextClassLoader(currentLoader);
   perstitencemanager = new MyClass();
  } finally {
   Thread.currentThread().setContextClassLoader(myclassloader );
  }


Then, it was able to read the persistence.xml file. I verified this by also testing the previous bundleresource patch lookup above.

However, in both cases I got the following error:

Code:
Unhandled event loop exception

Reason:

org.hibernate.cfg.Mappings.<init>(Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/List;Ljava/util/List;Lorg/hibernate/cfg/NamingStrategy;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/List;)V


Just an fyi, hopefully someone will find the classloader information above useful.

-D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 7:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
the last issue seems to be a version compatibility issue between hibernate core and HA or HEM. Be sure to use the appropriate versions (as stated in the docs)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 8:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
cool that autodiscovery now works from inside eclipse ;)

the classloader thingy is expected if you don't use eclipse buddy classloading (use google to find info about it)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 11:15 am 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
Emmanuel, thanks for following up - my symptom was indeed a versioning issue between CORE and EM.

I was using hibernate3-3.1rc3, when I dropped back to 3.1rc1 (as it is indeed documented as required for the -beta4 entity manager) I can confirm a fully-functional EJB3-embedded app running in Eclipse.

Thanks everyone!

-D


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 12:36 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
err...I know this is making the thread long, but I was using a patched version of entitymanager-3.1beta4.

The existing 3.1beta4 will work in the workbench, but not standalone/run as plugin. I did have to use the bundleresource patch on JarVisitor.java.

Code:
   public static final URL getJarURLFromURLEntry(URL url, String entry) throws IllegalArgumentException {
      URL jarUrl;
      String file = url.getFile();
      if ( ! entry.startsWith( "/" ) ) entry = "/" + entry;
      file = file.substring( 0, file.length() - entry.length() );
      if ( file.endsWith( "!") ) file = file.substring( 0, file.length() - 1 );
      try {
         System.out.println("getJarUrl: " + url);
         if ( "jar".equals( url.getProtocol() ) ) {
            jarUrl = new URL(file);
         }
         else if(url.getProtocol().startsWith("bundle")) {
            System.out.println("trying to get eclipse bundle.");
                 try {
                     Class p = Class.forName("org.eclipse.core.runtime.Platform");
                     java.lang.reflect.Method m = p.getMethod("resolve", URL.class);
                     jarUrl = (URL)m.invoke(null, url);
                     System.out.println("Got eclipse new url: " + jarUrl);
                  } catch (Exception e) {
                     throw new IllegalArgumentException("Can't get bundle url.", e);
                  }     
            }
         else {

            jarUrl = new URL( url.getProtocol(), url.getHost(), url.getPort(), file );
         }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 12:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so put this in the jira again. the reason it work from within a workbench launch is that it stuff will be on the global classpath which is not a bundle resource.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Guys, you realize that a solution involving a patch having
Code:
Class p = Class.forName("my.crappy.designed.Platform");

in it, is not a scalable solution.

Why doesn't they provide a proper
java.protocol.handler.pkgs.bundle.Handler
to work with such URLs...

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.