Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to deploy Hibernate on OSGi

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the ways to deploy Hibernate on OSGi. It is very detailed and has a certain reference value. Friends who are interested must read it!

OpenCore is a microkernel (Microkenerl) built on the OSGi specification, based on a pure component (Pure Plugin) open source enterprise application software platform. The OpenCore data layer implements the integration of Hibernate,Hibernate and its dependent libraries on OSGi as a separate plug-in, which brings a problem, that is, the plug-in class loading mechanism of the OSGi platform makes it impossible for Hibernate to correctly load the model objects and Hibernate R mapping files distributed within different plug-ins.

Model object (Domain Objects) plug-in

Model objects (Domain Objects) are centralized into separate plug-ins (Bundle), and Hibernate plug-ins rely on these model object plug-ins. This is the easiest and worst way to do this, and smaller OSGi-based projects can do the same.

Dependency mode:

Business plug-ins-> Hibernate plug-ins

| | |

| |\ | / |

|-Model plug-in

/

Improved Model object (Domain Objects) plug-in

Think of the model object plug-in as the Fragments of the Hibernate plug-in, as shown in the figure:

Business plug-ins-> Hibernate plug-ins

/ |\

| |

Model plug-in

Eclipse-BuddyPolicy and Eclipse-RegisterBuddy mode

The platform-specific approach of Equinox (OSGi implementation provided by Eclipse) allows plug-ins (Bundle) to declare their partners and "partner plug-ins" to dynamically load the plug-in's classes, which is also the official solution for Hiberate and Equinox integration. In this way, the model object does not need to be deployed in a separate plug-in, it can be deployed with the business plug-in, and the Hibernate plug-in does not have to rely on the model object.

The specific practices are as follows:

First, the Hibernate plug-in (name, for example, org.opengoss.orm.hibernate) declares itself as a partner plug-in, adding a description to the self-description file (MANIFEST.MF):

Eclipse-BuddyPolicy: registered

Then, the Hibernate plug-in is added as a partner in the business plug-in of the model object, and the self-description file (MANIFEST.MF) is added to the description:

Eclipse-RegisterBuddy:org.opengoss.orm.hibernate

Specific documentation:

Http://www.hibernate.org/311.html

Http://www.ibm.com/developerworks/cn/opensource/os-ecl-osgi/index.html

Note: this approach does not guarantee success in the latest version of Hibernate. You can try again:)

Eclipse Extension Point mode

This is the way we currently implement. Through the standard Eclipse extension point and extension mechanism, we declare the following extension points in the plugin.xml configuration file in the Hibernate plug-in:

Declare the extension in the model object plug-in, for example:

During the startup of the Hibernate plug-in, generate SessionFactory with code configuration as follows:

Public void start (BundleContext context) throws Exception {Configuration configuration = new Configuration (). Configure (new File (". / etc/org.opengoss.database.hibernate/hibernate.cfg.xml"); Class [] domainClasses = getDomainClasses (); for (Class domainClass: domainClasses) {configuration.addClass (domainClass);} sessionFactory = configuration.buildSessionFactory (); Dictionarynew Hashtableprops.put ("scope", "APPLICATION"); props.put ("uid", "Hibernate:SessionFactory"); registration = context.registerService (SessionFactory.class.getName (), sessionFactory, props) } private Class [] getDomainClasses () throws Exception {List domainClasses = new ArrayList (); IExtensionPoint point = registry.getExtensionPoint (IConstants.DOMAIN_OBJECT_EXTENSION_POINT); IExtension [] extensions = point.getExtensions (); for (IExtension extension: extensions) {IConfigurationElement [] elements = extension.getConfigurationElements (); for (IConfigurationElement configurationElement: elements) {Bundle bundle = pluginContext.getBundleBySymbolId (extension.getNamespaceIdentifier ()); Class domainClass = bundle.loadClass (configurationElement.getAttribute ("class")); domainClasses.add (domainClass) }} return domainClasses.toArray (new Class [domainClasses.size ()]);}

DynamicImport-Package: * Note: the class loading mechanism within Hibernate is really unsatisfactory. Although we have loaded all the model class objects in this way, Class.forName () is still called inside Hibernate to attempt to load. Therefore, we have to add a description to its self-description file (MANIFEST.MF):

These are all the contents of the article "what are the ways to deploy Hibernate on OSGi?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report