-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate & RCP: Mapping of entities distributed by plug
PostPosted: Thu Apr 03, 2008 5:33 am 
Newbie

Joined: Wed Apr 02, 2008 9:05 am
Posts: 8
Hi guys,

I want to creaze an Eclipse RCP application whose plugins should contribute their needed entity classes which themselves are persisted by the core application. Therefore, I have to add the entity classes and mapping files to Hibernate's configuration (e.g. by addClass()).

My problem is this case is that Hibernate cannot find the entity classes (distributed by the plugins) via reflection so that an ClassNotFoundException is thrown (the class references resolved by the rcp mechanism are correct).


Does anyone habe an idea or hint how this classloader problem in Hibernate with RCP can be solved?

Many thanks for your help.

With best regards,
RibbitHunter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2008 4:10 am 
Newbie

Joined: Wed Apr 02, 2008 9:05 am
Posts: 8
any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 2:19 am 
Newbie

Joined: Mon Apr 07, 2008 2:14 am
Posts: 2
Hi,

If you're still interested here's a solution:

You need to use the buddy policies of eclipse.

Write in youre hinbernate using core plugin manifest:
Eclipse-BuddyPolicy: registered

And in for every plugin with entities add the following to the Manifest.mf:
Eclipse-RegisterBuddy: id.of .your.core.plugin

You also need to add the core plugin as dependency to your entity plugins.

best regards
Hannes


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 6:27 am 
Newbie

Joined: Wed Apr 02, 2008 9:05 am
Posts: 8
Thanks for your reply.
I already have enabled the BuddyLoading-Feature and it seams to work correctly because the classes of the Hibernate libraries (wrapped in plugin) can be resolved.

Thats the code where the system crashes:

Code:
try{
          final IExtensionRegistry registry = Platform.getExtensionRegistry();
         final IExtensionPoint extensionPoint = registry.getExtensionPoint("org.me.proj.entity");
         final IExtension[] extensions = extensionPoint.getExtensions();
         
         Configuration config = new Configuration();
         
         for(final IExtension element : extensions) {
            for(IConfigurationElement c : element.getConfigurationElements()) {
               final String elementName = c.getName();
               
               if(elementName.equals("entity")){
                  IEntity entity = (IEntity)c.createExecutableExtension("class");
                  
                  final Bundle bundle = Platform.getBundle(c.getContributor().getName());
                  final URL mappingFileURL = bundle.getResource(c.getAttribute("mappingFile"));
                  
                  config.addResource(mappingFileURL.getPath(), entity.getClass().getClassLoader());
               }
            }
         }
       }
       catch(Exception exc) {
          exc.printStackTrace();
       }


I get the following stack trace:

Quote:
[...]
250 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.me.proj.explorer.opengl.api.EntityB -> entityb
org.hibernate.InvalidMappingException: Could not parse mapping document from resource /src/org/baer/pepe/explorer/opengl/api/EntityB.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:545)
at org.me.proj.ApplicationWorkbenchWindowAdvisor.postWindowOpen(ApplicationWorkbenchWindowAdvisor.java:73)
at org.eclipse.ui.internal.WorkbenchWindow.fireWindowOpened(WorkbenchWindow.java:1203)
at org.eclipse.ui.internal.WorkbenchWindow.open(WorkbenchWindow.java:762)
at org.eclipse.ui.internal.Workbench$21.runWithException(Workbench.java:1037)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3659)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3296)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:801)
at org.eclipse.ui.internal.Workbench$25.runWithException(Workbench.java:1342)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:152)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:118)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4097)
at org.eclipse.ui.internal.StartupThreading.runWithoutExceptions(StartupThreading.java:94)
at org.eclipse.ui.internal.Workbench.init(Workbench.java:1337)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2319)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.me.proj.Application.start(Application.java:21)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
at org.eclipse.equinox.launcher.Main.main(Main.java:1148)
Caused by: org.hibernate.MappingException: class org.me.proj.explorer.opengl.api.EntityB not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:279)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:401)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:334)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:675)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:510)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:542)
... 37 more
Caused by: java.lang.ClassNotFoundException: org.me.proj.explorer.opengl.api.EntityB
at java.lang.ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:429)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:369)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:357)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
... 45 more


The entity class distributed by a plugin can be resolved and I try to load the class by its own classloader. This does not work. Does anyone have an idea of the reason?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

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.