Java ServiceRegistry在创建SessionFactory中有什么用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21520368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the use of ServiceRegistry in creating SessionFactory
提问by Ankit Lamba
I am learning Hibernate in Java.
Since, to create a Session
, we have to use SessionFactory.openSession()
, and for creating SessionFactory
we use sessionFactory = config.buildSessionFactory(serviceRegistry);
我正在用 Java 学习 Hibernate。因为,要创建Session
,我们必须使用SessionFactory.openSession()
,并且要创建SessionFactory
我们使用sessionFactory = config.buildSessionFactory(serviceRegistry);
What is the use of ServiceRegistry
in hibernate??
ServiceRegistry
在休眠中有什么用??
My code for creating SessionFactory
:
我的创建代码SessionFactory
:
Configuration config = new Configuration();
config.addAnnotatedClass(user.class);
config.addAnnotatedClass(emp.class);
config.configure();
// Didn't understand the code below
Properties configProperties = config.getProperties();
ServiceRegistryBuilder serviceRegisteryBuilder = new ServiceRegistryBuilder();
ServiceRegistry serviceRegistry = serviceRegisteryBuilder.applySettings(configProperties).buildServiceRegistry();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
回答by Mahesh
Please refer Hibernate documentation (chapter 7) : http://docs.jboss.org/hibernate/core/4.0/devguide/en-US/html/ch07.html
请参考 Hibernate 文档(第 7 章):http: //docs.jboss.org/hibernate/core/4.0/devguide/en-US/html/ch07.html
Service : Services are classes that provide Hibernate with pluggable implementations of various types of functionality. Specifically they are implementations of certain service contract interfaces
服务 :服务是为 Hibernate 提供各种类型功能的可插入实现的类。具体来说,它们是某些服务契约接口的实现
ServiceRegistry : The central service API, aside from the services themselves, is the org.hibernate.service.ServiceRegistry interface. The main purpose of a service registry is to hold, manage and provide access to services.
ServiceRegistry :除了服务本身之外,中心服务 API 是 org.hibernate.service.ServiceRegistry 接口。服务注册的主要目的是保存、管理和提供对服务的访问。
回答by Gajendra Kotra
A ServiceRegistry, at its most basic, hosts and manages Services. Its contract is defined by the org.hibernate.service.ServiceRegistry interface. Currently Hibernate utilizes 3 different ServiceRegistry implementations forming a hierarchy.
ServiceRegistry 最基本的功能是托管和管理服务。它的契约由 org.hibernate.service.ServiceRegistry 接口定义。当前 Hibernate 使用 3 种不同的 ServiceRegistry 实现形成一个层次结构。
- BootstrapServiceRegistry
- StandardServiceRegistry
- SessionFactoryServiceRegistry org.hibernate.service.spi.SessionFactoryServiceRegistry is the 3rd standard Hibernate ServiceRegistry. Typically, its parent registry is the StandardServiceRegistry. SessionFactoryServiceRegistry is designed to hold Services which need access to the SessionFactory. Currently that is just 3 Services.
- 引导服务注册
- 标准服务注册表
- SessionFactoryServiceRegistry org.hibernate.service.spi.SessionFactoryServiceRegistry 是第三个标准的 Hibernate ServiceRegistry。通常,其父注册表是 StandardServiceRegistry。SessionFactoryServiceRegistry 旨在保存需要访问 SessionFactory 的服务。目前只有 3 个服务。
EventListenerRegistryorg.hibernate.event.service.spi.EventListenerRegistry is the big Service managed in the SessionFactoryServiceRegistry. This is the Service that manages and exposes all of Hibernate's event listeners. A major use-case for Integrators is to alter the listener registry.
EventListenerRegistryorg.hibernate.event.service.spi.EventListenerRegistry 是 SessionFactoryServiceRegistry 中管理的大服务。这是管理和公开所有 Hibernate 事件侦听器的服务。集成器的一个主要用例是更改侦听器注册表。
If doing custom listener registration, it is important to understand the org.hibernate.event.service.spi.DuplicationStrategy and its effect on registration. The basic idea is to tell Hibernate:
如果进行自定义监听器注册,了解 org.hibernate.event.service.spi.DuplicationStrategy 及其对注册的影响很重要。基本思想是告诉Hibernate:
what makes a listener a duplicate
是什么让听众成为重复的人
how to handle duplicate registrations (error, first wins, last wins)
如何处理重复注册(错误、首胜、末胜)
StatisticsImplementor
统计执行器
org.hibernate.stat.spi.StatisticsImplementor is the SPI portion of the org.hibernate.stat.Statistics API. The collector portion, if you will.
org.hibernate.stat.spi.StatisticsImplementor 是 org.hibernate.stat.Statistics API 的 SPI 部分。收集器部分,如果你愿意的话。
回答by Mahesh Bansode
Refer this : http://docs.jboss.org/hibernate/core/4.0/devguide/en-US/html/ch07.html
请参阅:http: //docs.jboss.org/hibernate/core/4.0/devguide/en-US/html/ch07.html
The central service API, aside from the services themselves, is the org.hibernate.service.ServiceRegistry interface. The main purpose of a service registry is to hold, manage and provide access to services.
除了服务本身之外,中心服务 API 是 org.hibernate.service.ServiceRegistry 接口。服务注册的主要目的是保存、管理和提供对服务的访问。
Service registries are hierarchical. Services in one registry can depend on and utilize services in that same registry as well as any parent registries.
服务注册表是分层的。一个注册中心中的服务可以依赖并利用同一个注册中心以及任何父注册中心中的服务。
Use org.hibernate.service.ServiceRegistryBuilder to build a org.hibernate.service.ServiceRegistry instance.
使用 org.hibernate.service.ServiceRegistryBuilder 构建一个 org.hibernate.service.ServiceRegistry 实例。