Using Hibernate with Dynamic Eclipse Plugins

I have classes that are equally called the different plugins that I use for my application, and I would like to be able to configure them correctly using Hibernate. The problem is that it looks like Hibernate is dynamically generating the class package name when trying to find a class when matching it. This scheme works with one plug-in, but it does not work through several plug-ins. Hibernate seems to get confused when working with Hibernate configuration files through multiple plug-ins.

Is it because each plugin has its own class loader? What is the best way to get started with existing plugins and Hibernate?

+4
source share
2 answers

The problem is that each plugin has its own class loader, and Hibernate uses Reflection to find the right classes.

I have a very good article at home about a specific problem, but it is in German. I will try to explain what you need to do.

To have a data structure shared by several plugins, you must put it in the plugin and enable a function called buddy policy . Suppose you have a main-application-plugin that starts hibernation at startup, this plugin should “see” the classes from the datastructure plugin. To do this , the main plugin sets its Buddy-Policy to “registered”, and the datastructure plugin registers as a “buddy” . Unfortunately, you have to do this directly in the manifest file, at least in 3.3, there was no way in the editor to do this.

Once this policy works, Hibernate will also be.

I looked through my old application and this is how I did it.

  • The main application (toolseye.rcp) depends on the hibernate plugin (de.eye4eye.hibernate) and the datastructure-plugin plugin (toolseye.datastructures)
  • The hibernate plugin defines its friend policy as "registered"
  • The datastructure module connects to the sleep plugin

Here are the important lines:

Hibernate-plugin de.eye4eye.hibernate

Eclipse-BuddyPolicy: registered 

Tool files with tool structures.

 Eclipse-RegisterBuddy: de.eye4eye.hibernate 

Put this line directly in MANIFEST.MF

Both plugins must re-export their packages so that the main application or any other layer that you have between them can use them. Hope this helps.

+4
source

Just to make it complete.

Instead of using Hibernate, EclipseLink can be used as a JPA provider in an Eclipse RCP application. EclipseLink is a former TopLink from Oracle and was selected for the reference implementation for JPA 2.

The point for RCP is that EclipseLink is available as OSGI-Bundles (org.eclipse.persistence.jpa), and so it can load classes from another plugin without an additional partner policy.

I currently played using the following project structure (Model-View-Presenter Pattern). Names in brackets indicate dependecy plugins (not all are included, only those related to this question)

  • rcp.mvp.view (rcp.mvp.presenter / rcp.mvp.model)
  • rcp.mvp.presenter (rcp.mvp.data - the data will re-export the model, so this is not required here) *
  • rcp.mvp.data strong> (rcp.mvp.data.mysql / rcp.mvp.model / javax.persistence / org.eclipse.persistence.jpa)
  • rcp.mvp.data.mysql - provides only mysql-jdbc-driver. must be inside the classpath
  • rcp.mvp.model

In this case, the JPA provider in the data plug-in can load classes from the plug-in module without a contact policy.

* Note. The host is not dependent on any JPA packages because it is encapsulated by the DAO (the main reason why they are used)

References

+1
source

All Articles