From 0b10334e403cf2b11ee60725cc5619eaafecc00b Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Mon, 7 Mar 2011 13:40:06 -0800 Subject: [PATCH] HHH-5991 : add Configuration.buildSessionFactory() (without ServiceRegistry arg) --- .../java/org/hibernate/cfg/Configuration.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index 8e8a0d17f1..698a8e47d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -158,6 +158,7 @@ import org.hibernate.mapping.TypeDef; import org.hibernate.mapping.UniqueKey; import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.secure.JACCConfiguration; +import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.spi.ServiceRegistry; import org.hibernate.tool.hbm2ddl.DatabaseMetadata; import org.hibernate.tool.hbm2ddl.IndexMetadata; @@ -1850,6 +1851,36 @@ public class Configuration implements Serializable { ); } + /** + * Create a {@link SessionFactory} using the properties and mappings in this configuration. The + * {@link SessionFactory} will be immutable, so changes made to {@code this} {@link Configuration} after + * building the {@link SessionFactory} will not affect it. + * + * @return The build {@link SessionFactory} + * + * @throws HibernateException usually indicates an invalid configuration or invalid mapping information + * + * @deprecated Use {@link #buildSessionFactory(ServiceRegistry)} instead + */ + public SessionFactory buildSessionFactory() throws HibernateException { + Environment.verifyProperties( properties ); + ConfigurationHelper.resolvePlaceHolders( properties ); + final ServiceRegistry serviceRegistry = new ServiceRegistryImpl( properties ); + setSessionFactoryObserver( + new SessionFactoryObserver() { + @Override + public void sessionFactoryCreated(SessionFactory factory) { + } + + @Override + public void sessionFactoryClosed(SessionFactory factory) { + ( (ServiceRegistryImpl ) serviceRegistry ).destroy(); + } + } + ); + return buildSessionFactory( serviceRegistry ); + } + private static final String LEGACY_VALIDATOR_EVENT_LISTENER = "org.hibernate.validator.event.ValidateEventListener"; private void enableLegacyHibernateValidator() {