如何从Eclipse插件中使用Hibernate?

时间:2023-01-12 13:15:27

I am writing an Eclipse plug-in that loads resources from a central database. I would like to use Hibernate to access that database.

我正在编写一个Eclipse插件,它从*数据库加载资源。我想使用Hibernate来访问该数据库。

So how would I add this as a dependency to my plug-in project? I've tried Google but only get hits on about plug-ins for editing Hibernate configuration files.

那么我如何将它作为依赖项添加到我的插件项目中呢?我已经尝试过谷歌,但只能点击关于编辑Hibernate配置文件的插件。

2 个解决方案

#1


1  

I would create a hibernate plugin, that exposes all the hibernate jar files and exports the classes contained. My configuration and data would then be in another plugin that depends on hibernate.

我会创建一个hibernate插件,它公开所有的hibernate jar文件并导出包含的类。我的配置和数据将在另一个依赖于休眠的插件中。

Then, because hibernate uses reflection like no tomorrow, the Hibernate plug-in needs to be able to load classes from the plug ins that depend on it. To do that you need to use the Eclipse-BuddyPolicy directive. Check this documentation on classloading on eclipse that mentions BuddyPolicy

然后,因为hibernate使用反射而不是明天,所以Hibernate插件需要能够从依赖它的插件中加载类。为此,您需要使用Eclipse-BuddyPolicy指令。查看有关提及BuddyPolicy的eclipse上的类加载的文档

I've set up a Kodo JDO plug-in using this technique and it works quite well. A sample from my Manifest.mf is attached

我使用这种技术设置了一个Kodo JDO插件,效果很好。我的Manifest.mf中附有一个样本

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Solarmetric Kodo
Bundle-SymbolicName: com.solarmetric.kodo
Bundle-Activator: com.solarmetric.kodo.KodoPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime
Eclipse-AutoStart: true
Eclipse-BuddyPolicy: global
Export-Package: com.solarmetric.ant,
 com.solarmetric.apache.commons.collections,
 com.solarmetric.apache.commons.collections.buffer,
 com.solarmetric.apache.commons.collections.collection,
 com.solarmetric.apache.commons.collections.functors,
 com.solarmetric.apache.commons.collections.iterators,
 com.solarmetric.apache.commons.collections.keyvalue,

#2


0  

You could stick to the standard hibernate tutorials like the documentation provided at hibernate.org or Gaven Kings book, for using hibernate in combination within an eclipse rcp project.

您可以坚持使用标准的hibernate教程,例如hibernate.org或Gaven Kings书中提供的文档,以便在eclipse rcp项目中结合使用hibernate。

The simplest way would be to include your Hibernate related code and your config in the plugin you currently develop.

最简单的方法是在您当前开发的插件中包含与Hibernate相关的代码和配置。

Therefore your plugin has to depend on the jar files, each hibernate projects depends on. You could also provide these libs by a separated plugin and simply export them.

因此你的插件必须依赖于jar文件,每个hibernate项目都依赖于。您还可以通过单独的插件提供这些库,然后只需导出它们。

But you have to keep in mind that hibernate makes heavy use of reflection and your persistable classes have to be accessible for your persistence manager.

但是你必须记住,hibernate大量使用反射,你的持久化管理器必须可以访问你的可持久化类。

There is also a very good tutorial for integrating hibernate as a separate plugin on http://entwickler.de/zonen/portale/psecom,id,101,online,1082,.html but unfortunately it is only in german.

还有一个非常好的教程,可以将hibernate作为一个单独的插件集成到http://entwickler.de/zonen/portale/psecom,id,101,online,1082,.html但不幸的是它只是在德语中。

#1


1  

I would create a hibernate plugin, that exposes all the hibernate jar files and exports the classes contained. My configuration and data would then be in another plugin that depends on hibernate.

我会创建一个hibernate插件,它公开所有的hibernate jar文件并导出包含的类。我的配置和数据将在另一个依赖于休眠的插件中。

Then, because hibernate uses reflection like no tomorrow, the Hibernate plug-in needs to be able to load classes from the plug ins that depend on it. To do that you need to use the Eclipse-BuddyPolicy directive. Check this documentation on classloading on eclipse that mentions BuddyPolicy

然后,因为hibernate使用反射而不是明天,所以Hibernate插件需要能够从依赖它的插件中加载类。为此,您需要使用Eclipse-BuddyPolicy指令。查看有关提及BuddyPolicy的eclipse上的类加载的文档

I've set up a Kodo JDO plug-in using this technique and it works quite well. A sample from my Manifest.mf is attached

我使用这种技术设置了一个Kodo JDO插件,效果很好。我的Manifest.mf中附有一个样本

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Solarmetric Kodo
Bundle-SymbolicName: com.solarmetric.kodo
Bundle-Activator: com.solarmetric.kodo.KodoPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime
Eclipse-AutoStart: true
Eclipse-BuddyPolicy: global
Export-Package: com.solarmetric.ant,
 com.solarmetric.apache.commons.collections,
 com.solarmetric.apache.commons.collections.buffer,
 com.solarmetric.apache.commons.collections.collection,
 com.solarmetric.apache.commons.collections.functors,
 com.solarmetric.apache.commons.collections.iterators,
 com.solarmetric.apache.commons.collections.keyvalue,

#2


0  

You could stick to the standard hibernate tutorials like the documentation provided at hibernate.org or Gaven Kings book, for using hibernate in combination within an eclipse rcp project.

您可以坚持使用标准的hibernate教程,例如hibernate.org或Gaven Kings书中提供的文档,以便在eclipse rcp项目中结合使用hibernate。

The simplest way would be to include your Hibernate related code and your config in the plugin you currently develop.

最简单的方法是在您当前开发的插件中包含与Hibernate相关的代码和配置。

Therefore your plugin has to depend on the jar files, each hibernate projects depends on. You could also provide these libs by a separated plugin and simply export them.

因此你的插件必须依赖于jar文件,每个hibernate项目都依赖于。您还可以通过单独的插件提供这些库,然后只需导出它们。

But you have to keep in mind that hibernate makes heavy use of reflection and your persistable classes have to be accessible for your persistence manager.

但是你必须记住,hibernate大量使用反射,你的持久化管理器必须可以访问你的可持久化类。

There is also a very good tutorial for integrating hibernate as a separate plugin on http://entwickler.de/zonen/portale/psecom,id,101,online,1082,.html but unfortunately it is only in german.

还有一个非常好的教程,可以将hibernate作为一个单独的插件集成到http://entwickler.de/zonen/portale/psecom,id,101,online,1082,.html但不幸的是它只是在德语中。