Top Description Inners Fields Constructors Methods
org.hibernate.cfg

public Class Configuration

extends Object
Class Inheritance
Imports
java.io.File, .InputStream, java.net.URL, java.util.ArrayList, .HashMap, .List, .Map, .Properties, org.hibernate.CustomEntityDirtinessStrategy, .EntityNameResolver, .HibernateException, .Incubating, .Interceptor, .Internal, .MappingException, .SessionFactory, .SessionFactoryObserver, org.hibernate.boot.Metadata, .MetadataBuilder, .MetadataSources, .SessionFactoryBuilder, org.hibernate.boot.internal.ClassmateContext, org.hibernate.boot.jaxb.spi.Binding, org.hibernate.boot.model.FunctionContributor, .NamedEntityGraphDefinition, .TypeContributor, org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor, .InstanceBasedConverterDescriptor, org.hibernate.boot.model.convert.spi.ConverterDescriptor, org.hibernate.boot.model.naming.ImplicitNamingStrategy, .ImplicitNamingStrategyJpaCompliantImpl, .PhysicalNamingStrategy, .PhysicalNamingStrategyStandardImpl, org.hibernate.boot.model.relational.AuxiliaryDatabaseObject, .ColumnOrderingStrategy, org.hibernate.boot.query.NamedHqlQueryDefinition, .NamedNativeQueryDefinition, .NamedProcedureCallDefinition, .NamedResultSetMappingDescriptor, org.hibernate.boot.registry.BootstrapServiceRegistry, .BootstrapServiceRegistryBuilder, .StandardServiceRegistry, .StandardServiceRegistryBuilder, org.hibernate.boot.spi.XmlMappingBinderAccess, org.hibernate.context.spi.CurrentTenantIdentifierResolver, org.hibernate.internal.CoreLogging, .CoreMessageLogger, .EmptyInterceptor, org.hibernate.proxy.EntityNotFoundDelegate, org.hibernate.query.sqm.function.SqmFunctionDescriptor, org.hibernate.resource.jdbc.spi.StatementInspector, org.hibernate.service.ServiceRegistry, org.hibernate.type.BasicType, .SerializationException, org.hibernate.usertype.UserType, jakarta.persistence.AttributeConverter, .SharedCacheMode

A convenience API making it easier to bootstrap an instance of Hibernate.

An instance of Configuration may be obtained simply by instantiation, and may be used to aggregate:

Note that XML mappings may be expressed using the JPA orm.xml format, or in Hibernate's legacy .hbm.xml format.

Configuration properties are enumerated by AvailableSettings.

 SessionFactory factory = new Configuration()
    // scan classes for mapping annotations
    .addAnnotatedClass(Item.class)
    .addAnnotatedClass(Bid.class)
    .addAnnotatedClass(User.class)
    // read package-level annotations of the named package
    .addPackage("org.hibernate.auction")
    // set a configuration property
    .setProperty(AvailableSettings.DATASOURCE,
                 "java:comp/env/jdbc/test")
    .getSessionFactory();

In addition, there are convenience methods for adding attribute converters, type contributors, entity name resolvers, SQL function descriptors, and auxiliary database objects, for setting naming strategies and a tenant id resolver, and more.

Finally, an instance of SessionFactoryBuilder is obtained by calling buildSessionFactory().

Ultimately, this class simply delegates to MetadataBuilder and StandardServiceRegistryBuilder to actually do the hard work of building the SessionFactory. Programs may directly use the APIs defined under org.hibernate.boot, as an alternative to using an instance of this class.

Authors
Gavin King, Steve Ebersole
See Also
SessionFactory, AvailableSettings, org.hibernate.boot

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface

Field Summary

Modifier and TypeField and Description
public static final String
ARTEFACT_PROCESSING_ORDER

Deprecated for removal since 6.
private HashMap<Class<?>, ConverterDescriptor>
private List<AuxiliaryDatabaseObject>
private final List<BasicType<?>>
private final BootstrapServiceRegistry
private final ClassmateContext
private ColumnOrderingStrategy
private CurrentTenantIdentifierResolver<Object>
private CustomEntityDirtinessStrategy
private Map<String, SqmFunctionDescriptor>
private List<EntityNameResolver>
private EntityNotFoundDelegate
private final List<FunctionContributor>
private ImplicitNamingStrategy
private Interceptor
private static final CoreMessageLogger
private final MetadataSources
private Map<String, NamedEntityGraphDefinition>
private Map<String, NamedProcedureCallDefinition>
private Map<String, NamedHqlQueryDefinition>
private Map<String, NamedNativeQueryDefinition>
private PhysicalNamingStrategy
private Properties
private SessionFactoryObserver
private SharedCacheMode
private Map<String, NamedResultSetMappingDescriptor>
private StandardServiceRegistryBuilder
private StatementInspector
private final List<TypeContributor>
private List<Configuration.UserTypeRegistration>

Constructor Summary

AccessConstructor and Description
public
Configuration()

Create a new instance, using a default BootstrapServiceRegistry and a newly instantiated MetadataSources.

public
Configuration(BootstrapServiceRegistry serviceRegistry)

Create a new instance, using the given BootstrapServiceRegistry and a newly instantiated MetadataSources.

public
Configuration(MetadataSources metadataSources)

Create a new instance, using the given MetadataSources, and a BootstrapServiceRegistry obtained from the MetadataSources.

Method Summary

Modifier and TypeMethod and Description
public Configuration

Returns:

this for method chaining
addAnnotatedClass
(Class<T>
The class containing annotations
annotatedClass
)

Read metadata from the annotations associated with this class.

public Configuration

Returns:

this for method chaining
addAttributeConverter
(Class<? extends AttributeConverter<?, ?>>
The AttributeConverter class.
attributeConverterClass
,
boolean
Should the AttributeConverter be auto applied to property types as specified by its "entity attribute" parameterized type?
autoApply
)

Adds an AttributeConverter to this configuration.

public Configuration

Returns:

this for method chaining
addAttributeConverter
(Class<? extends AttributeConverter<?, ?>>
The AttributeConverter class.
attributeConverterClass
)

Adds an AttributeConverter to this configuration.

public Configuration

Returns:

this for method chaining
addAttributeConverter
(AttributeConverter<?, ?>
The AttributeConverter instance.
attributeConverter
)

Adds an AttributeConverter instance to this configuration.

public Configuration

Returns:

this for method chaining
addAttributeConverter
(AttributeConverter<?, ?>
The AttributeConverter instance.
attributeConverter
,
boolean
Should the AttributeConverter be auto applied to property types as specified by its "entity attribute" parameterized type?
autoApply
)

Adds an AttributeConverter instance to this configuration.

public Configuration

Returns:

this for method chaining
addAttributeConverter
(ConverterDescriptor
The ConverterDescriptor instance.
converterDescriptor
)

Adds an ConverterDescriptor instance to this configuration.

public Configuration

Returns:

this for method chaining
addAuxiliaryDatabaseObject
(AuxiliaryDatabaseObject object)

Adds an AuxiliaryDatabaseObject to this configuration.

public Configuration

Returns:

this for method chaining
addCacheableFile
(File
The cacheable mapping file to be added.
xmlFile
)

Add a cacheable mapping file.

public Configuration

Returns:

this for method chaining
addCacheableFile
(String
The name of the file to be added, in a form usable to simply construct a File instance
xmlFile
)

Add a cacheable mapping file.

public Configuration

Returns:

this for method chaining
addCacheableFileStrictly
(File
The xml file, not the bin!
xmlFile
)

INTENDED FOR TESTSUITE USE ONLY!

public Configuration

Returns:

this for method chaining
addClass
(Class<T>
The mapped class
entityClass
)

Read a mapping as an application resource using the convention that a class named foo.bar.Foo is mapped by a file foo/bar/Foo.hbm.xml which can be resolved as a classpath resource.

public Configuration

Returns:

this for method chaining
addDirectory
(File
The directory
dir
)

Read all .hbm.xml mapping documents from a directory tree.

public Configuration

Returns:

this for method chaining
addEntityNameResolver
(EntityNameResolver
The EntityNameResolver instance.
entityNameResolver
)

Add an EntityNameResolver to this configuration.

public Configuration

Returns:

this for method chaining
addFile
(String
a path to a file
xmlFile
)

Read mappings from a particular XML file

public Configuration

Returns:

this for method chaining
addFile
(File
a path to a file
xmlFile
)

Read mappings from a particular XML file.

public Configuration

Returns:

this for method chaining
addInputStream
(InputStream
The input stream containing a DOM.
xmlInputStream
)

Read mappings from an InputStream.

public Configuration

Returns:

this for method chaining
addJar
(File
a jar file
jar
)

Read all .hbm.xml mappings from a .jar file.

public Configuration

Returns:

this for method chaining
addPackage
(String
java package name
packageName
)

Read package-level metadata.

public Configuration

Returns:

this for method chaining
addProperties
(Properties
The properties to add.
properties
)

Add the given properties to ours.

public Configuration

Returns:

this for method chaining
addResource
(String
The resource name
resourceName
)

Read mappings as an application resource name, that is, using a classpath lookup, trying different class loaders in turn.

public Configuration

Returns:

this for method chaining
addSqlFunction
(String functionName, SqmFunctionDescriptor function)

Adds a SQL function descriptor to this configuration.

public Configuration

Returns:

this for method chaining
addURL
(URL
The url for the mapping document to be read.
url
)

Read mappings from a URL.

public Configuration

Returns:

this for method chaining
addXmlMapping
(Binding<?>
the parsed mapping
binding
)

Read mappings that were parsed using getXmlMappingBinderAccess().

public SessionFactory

Returns:

The newly-built SessionFactory
buildSessionFactory
(ServiceRegistry
The registry of services to be used in creating this session factory.
serviceRegistry
)

Create a SessionFactory using the properties and mappings in this configuration.

public SessionFactory

Returns:

The newly-built SessionFactory
buildSessionFactory
()

Create a SessionFactory using the properties and mappings in this configuration.

public Configuration

Returns:

this for method chaining
configure
()

Use the mappings and properties specified in an application resource named hibernate.cfg.xml.

public Configuration

Returns:

this for method chaining
configure
(String
The resource to use
resource
)

Use the mappings and properties specified in the given application resource.

public Configuration

Returns:

this for method chaining
configure
(URL
URL from which you wish to load the configuration
url
)

Use the mappings and properties specified in the given document.

public Configuration

Returns:

this for method chaining
configure
(File
File from which you wish to load the configuration
configFile
)

Use the mappings and properties specified in the given application file.

private XmlMappingBinderAccess
private static BootstrapServiceRegistry
public ColumnOrderingStrategy
getColumnOrderingStrategy()

The CustomEntityDirtinessStrategy, if any, that was added to this configuration.

public CurrentTenantIdentifierResolver<Object>
getCurrentTenantIdentifierResolver()

The CurrentTenantIdentifierResolver, if any, that was added to this configuration.

public CustomEntityDirtinessStrategy
getCustomEntityDirtinessStrategy()

The CustomEntityDirtinessStrategy, if any, that was added to this configuration.

public EntityNotFoundDelegate

Returns:

The user-supplied delegate
getEntityNotFoundDelegate
()

Retrieve the user-supplied EntityNotFoundDelegate, or null if no delegate has been specified.

public ImplicitNamingStrategy
getImplicitNamingStrategy()

The ImplicitNamingStrategy, if any, to use in this configuration.

public Interceptor

Returns:

The current Interceptor
getInterceptor
()

Retrieve the configured Interceptor.

public Collection<NamedEntityGraphDefinition>
public Map<String, NamedProcedureCallDefinition>
public Map<String, NamedHqlQueryDefinition>
public Map<String, NamedNativeQueryDefinition>
public PhysicalNamingStrategy
getPhysicalNamingStrategy()

The PhysicalNamingStrategy, if any, to use in this configuration.

public Properties

Returns:

all properties
getProperties
()

Get all properties

public String

Returns:

The value currently associated with that property name; may be null.
getProperty
(String
The name of the property
propertyName
)

Get a property value by name

public SessionFactoryObserver
getSessionFactoryObserver()

The SessionFactoryObserver, if any, that was added to this configuration.

public Map<String, SqmFunctionDescriptor>
public Map<String, NamedResultSetMappingDescriptor>
public StandardServiceRegistryBuilder
getStandardServiceRegistryBuilder()

Intended for internal testing use only!!!

public StatementInspector
getStatementInspector()

The StatementInspector, if any, that was added to this configuration.

public XmlMappingBinderAccess
getXmlMappingBinderAccess()

An object capable of parsing XML mapping files that can then be passed to addXmlMapping(Binding).

public Configuration

Returns:

this for method chaining
mergeProperties
(Properties
The properties to merge
properties
)

Adds the incoming properties to the internal properties structure, as long as the internal structure does not already contain an entry for the given key.

public Configuration

Returns:

this for method chaining
registerFunctionContributor
(FunctionContributor functionContributor)

Add a FunctionContributor to this configuration.

public Configuration

Returns:

this for method chaining
registerTypeContributor
(TypeContributor typeContributor)

Add a TypeContributor to this configuration.

public Configuration

Returns:

this for method chaining
registerTypeOverride
(BasicType<?>
The type to register.
type
)

Register a type into the type registry, potentially replacing a previously registered type.

public Configuration

Returns:

this for method chaining
registerTypeOverride
(UserType<?>
The type to register.
type
,
String[]
The keys under which to register the type.
keys
)

Register a type into the type registry, potentially replacing a previously registered type.

protected void
public Configuration

Returns:

this for method chaining
setColumnOrderingStrategy
(ColumnOrderingStrategy columnOrderingStrategy)

Specify a CustomEntityDirtinessStrategy to be added to this configuration.

public Configuration

Returns:

this for method chaining
setCurrentTenantIdentifierResolver
(CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver)

Specify a CurrentTenantIdentifierResolver to be added to this configuration.

public Configuration

Returns:

this for method chaining
setCustomEntityDirtinessStrategy
(CustomEntityDirtinessStrategy customEntityDirtinessStrategy)

Specify a CustomEntityDirtinessStrategy to be added to this configuration.

public Configuration

Returns:

this for method chaining
setEntityNotFoundDelegate
(EntityNotFoundDelegate
The delegate to use
entityNotFoundDelegate
)

Specify a user-supplied EntityNotFoundDelegate to be used to handle scenarios where an entity could not be located by specified id.

public Configuration

Returns:

this for method chaining
setImplicitNamingStrategy
(ImplicitNamingStrategy implicitNamingStrategy)

Set an ImplicitNamingStrategy to use in this configuration.

public Configuration

Returns:

this for method chaining
setInterceptor
(Interceptor
The Interceptor to use
interceptor
)

Set the current Interceptor.

public Configuration

Returns:

this for method chaining
setPhysicalNamingStrategy
(PhysicalNamingStrategy physicalNamingStrategy)

Set a PhysicalNamingStrategy to use in this configuration.

public Configuration

Returns:

this for method chaining
setProperties
(Properties
The new set of properties
properties
)

Specify a completely new set of properties

public Configuration

Returns:

this for method chaining
setProperty
(String
The name of the property to set
propertyName
,
String
The new property value
value
)

Set a property value by name

public Configuration

Returns:

this for method chaining
setSessionFactoryObserver
(SessionFactoryObserver sessionFactoryObserver)

Specify a SessionFactoryObserver to be added to this configuration.

public Configuration

Returns:

this for method chaining
setSharedCacheMode
(SharedCacheMode
The SharedCacheMode to use
sharedCacheMode
)

Sets the SharedCacheMode to use.

public Configuration

Returns:

this for method chaining
setStatementInspector
(StatementInspector statementInspector)

Specify a StatementInspector to be added to this configuration.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait