public class Configuration extends Object
SessionFactory
in one-shot. The configuration
and mapping sources defined here are just held here until the SessionFactory is built. This
is an important distinction from the legacy behavior of this class, where we would try to
incrementally build the mappings from sources as they were added. The ramification of this
change in behavior is that users can add configuration and mapping sources here, but they can
no longer query the in-flight state of mappings (PersistentClass
,
Collection
, etc) here.
Note: Internally this class uses the new bootstrapping approach when asked to build the
SessionFactory.SessionFactory
Modifier and Type | Field and Description |
---|---|
static String |
ARTEFACT_PROCESSING_ORDER |
Constructor and Description |
---|
Configuration() |
Configuration(BootstrapServiceRegistry serviceRegistry) |
Configuration(MetadataSources metadataSources) |
Modifier and Type | Method and Description |
---|---|
void |
add(XmlDocument metadataXml)
Deprecated.
No longer supported.
|
Configuration |
addAnnotatedClass(Class annotatedClass)
Read metadata from the annotations associated with this class.
|
void |
addAttributeConverter(AttributeConverter attributeConverter)
Adds the AttributeConverter instance to this Configuration.
|
void |
addAttributeConverter(AttributeConverter attributeConverter,
boolean autoApply)
Adds the AttributeConverter instance to this Configuration.
|
void |
addAttributeConverter(AttributeConverterDefinition definition) |
void |
addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass)
Adds the AttributeConverter Class to this Configuration.
|
void |
addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass,
boolean autoApply)
Adds the AttributeConverter Class to this Configuration.
|
void |
addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object) |
Configuration |
addCacheableFile(File xmlFile)
Add a cached mapping file.
|
Configuration |
addCacheableFile(String xmlFile)
Add a cacheable mapping file.
|
Configuration |
addCacheableFileStrictly(File xmlFile)
INTENDED FOR TESTSUITE USE ONLY!
Much like
addCacheableFile(File) except that here we will fail immediately if
the cache version cannot be found or used for whatever reason |
Configuration |
addClass(Class persistentClass)
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.
|
Configuration |
addDirectory(File dir)
Read all mapping documents from a directory tree.
|
Configuration |
addDocument(Document doc)
Deprecated.
Use addURL, addResource, addFile, etc. instead
|
Configuration |
addFile(File xmlFile)
Read mappings from a particular XML file
|
Configuration |
addFile(String xmlFile)
Read mappings from a particular XML file
|
Configuration |
addInputStream(InputStream xmlInputStream)
Read mappings from an
InputStream . |
Configuration |
addJar(File jar)
Read all mappings from a jar file
Assumes that any file named *.hbm.xml is a mapping document.
|
Configuration |
addPackage(String packageName)
Read package-level metadata.
|
Configuration |
addProperties(Properties properties)
Add the given properties to ours.
|
Configuration |
addResource(String resourceName)
Read mappings as a application resourceName (i.e.
|
Configuration |
addResource(String resourceName,
ClassLoader classLoader)
Deprecated.
This form (accepting a ClassLoader) is no longer supported. Instead, add the ClassLoader
to the ClassLoaderService on the ServiceRegistry associated with this Configuration
|
void |
addSqlFunction(String functionName,
SQLFunction function) |
Configuration |
addURL(URL url)
Read mappings from a URL
|
Configuration |
addXML(String xml)
Deprecated.
No longer supported
|
void |
buildMappings()
Deprecated.
Does nothing
|
SessionFactory |
buildSessionFactory()
Create a
SessionFactory using the properties and mappings in this configuration. |
SessionFactory |
buildSessionFactory(ServiceRegistry serviceRegistry)
Create a
SessionFactory using the properties and mappings in this configuration. |
Configuration |
configure()
Use the mappings and properties specified in an application resource named hibernate.cfg.xml.
|
Configuration |
configure(Document document)
Deprecated.
No longer supported.
|
Configuration |
configure(File configFile)
Use the mappings and properties specified in the given application file.
|
Configuration |
configure(String resource)
Use the mappings and properties specified in the given application resource.
|
Configuration |
configure(URL url)
Use the mappings and properties specified in the given document.
|
CurrentTenantIdentifierResolver |
getCurrentTenantIdentifierResolver() |
EntityNotFoundDelegate |
getEntityNotFoundDelegate()
Retrieve the user-supplied delegate to handle non-existent entity
scenarios.
|
EntityTuplizerFactory |
getEntityTuplizerFactory() |
Interceptor |
getInterceptor()
Retrieve the configured
Interceptor . |
Collection<NamedEntityGraphDefinition> |
getNamedEntityGraphs() |
Map<String,NamedProcedureCallDefinition> |
getNamedProcedureCallMap() |
Map<String,NamedQueryDefinition> |
getNamedQueries() |
Map |
getNamedSQLQueries() |
Properties |
getProperties()
Get all properties
|
String |
getProperty(String propertyName)
Get a property value by name
|
SessionFactoryObserver |
getSessionFactoryObserver() |
Map<String,SQLFunction> |
getSqlFunctions() |
Map |
getSqlResultSetMappings() |
StandardServiceRegistryBuilder |
getStandardServiceRegistryBuilder()
Intended for internal testing use only!!!
|
Configuration |
mergeProperties(Properties 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.
|
Configuration |
registerTypeContributor(TypeContributor typeContributor) |
Configuration |
registerTypeOverride(BasicType type)
Allows registration of a type into the type registry.
|
Configuration |
registerTypeOverride(CompositeUserType type,
String[] keys) |
Configuration |
registerTypeOverride(UserType type,
String[] keys) |
protected void |
reset() |
void |
setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) |
void |
setEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate)
Specify a user-supplied delegate to be used to handle scenarios where an entity could not be
located by specified id.
|
void |
setImplicitNamingStrategy(ImplicitNamingStrategy implicitNamingStrategy) |
Configuration |
setInterceptor(Interceptor interceptor)
Set the current
Interceptor |
void |
setPhysicalNamingStrategy(PhysicalNamingStrategy physicalNamingStrategy) |
Configuration |
setProperties(Properties properties)
Specify a completely new set of properties
|
Configuration |
setProperty(String propertyName,
String value)
Set a property value by name
|
void |
setSessionFactoryObserver(SessionFactoryObserver sessionFactoryObserver) |
void |
setSharedCacheMode(SharedCacheMode sharedCacheMode)
Sets the SharedCacheMode to use.
|
public static final String ARTEFACT_PROCESSING_ORDER
public Configuration()
public Configuration(BootstrapServiceRegistry serviceRegistry)
public Configuration(MetadataSources metadataSources)
protected void reset()
public Properties getProperties()
public Configuration setProperties(Properties properties)
properties
- The new set of propertiespublic String getProperty(String propertyName)
propertyName
- The name of the propertypublic Configuration setProperty(String propertyName, String value)
propertyName
- The name of the property to setvalue
- The new property valuepublic Configuration addProperties(Properties properties)
properties
- The properties to add.public void setImplicitNamingStrategy(ImplicitNamingStrategy implicitNamingStrategy)
public void setPhysicalNamingStrategy(PhysicalNamingStrategy physicalNamingStrategy)
public Configuration configure() throws HibernateException
HibernateException
- Generally indicates we cannot find hibernate.cfg.xmlconfigure(String)
public Configuration configure(String resource) throws HibernateException
resource
- The resource to useHibernateException
- Generally indicates we cannot find the named resourcepublic StandardServiceRegistryBuilder getStandardServiceRegistryBuilder()
public Configuration configure(URL url) throws HibernateException
url
- URL from which you wish to load the configurationHibernateException
- Generally indicates a problem access the urlpublic Configuration configure(File configFile) throws HibernateException
configFile
- File from which you wish to load the configurationHibernateException
- Generally indicates a problem access the file@Deprecated public Configuration configure(Document document) throws HibernateException
HibernateException
public Configuration registerTypeContributor(TypeContributor typeContributor)
public Configuration registerTypeOverride(BasicType type)
type
- The type to register.public Configuration registerTypeOverride(UserType type, String[] keys)
public Configuration registerTypeOverride(CompositeUserType type, String[] keys)
public Configuration addFile(String xmlFile) throws MappingException
xmlFile
- a path to a fileMappingException
- Indicates inability to locate or parse
the specified mapping file.addFile(java.io.File)
public Configuration addFile(File xmlFile) throws MappingException
xmlFile
- a path to a fileMappingException
- Indicates inability to locate the specified mapping file.@Deprecated public void add(XmlDocument metadataXml)
public Configuration addCacheableFile(File xmlFile) throws MappingException
xmlFile
- The cacheable mapping file to be added.MappingException
- Indicates problems reading the cached file or processing
the non-cached file.public Configuration addCacheableFileStrictly(File xmlFile) throws SerializationException, FileNotFoundException
addCacheableFile(File)
except that here we will fail immediately if
the cache version cannot be found or used for whatever reasonxmlFile
- The xml file, not the bin!SerializationException
- Indicates a problem deserializing the cached dom treeFileNotFoundException
- Indicates that the cached file was not found or was not usable.public Configuration addCacheableFile(String xmlFile) throws MappingException
xmlFile
- The name of the file to be added. This must be in a form
useable to simply construct a File
instance.MappingException
- Indicates problems reading the cached file or processing
the non-cached file.addCacheableFile(java.io.File)
@Deprecated public Configuration addXML(String xml) throws MappingException
MappingException
public Configuration addURL(URL url) throws MappingException
url
- The url for the mapping document to be read.MappingException
- Indicates problems reading the URL or processing
the mapping document.@Deprecated public Configuration addDocument(Document doc) throws MappingException
doc
- The DOM documentMappingException
- Indicates problems reading the DOM or processing
the mapping document.public Configuration addInputStream(InputStream xmlInputStream) throws MappingException
InputStream
.xmlInputStream
- The input stream containing a DOM.MappingException
- Indicates problems reading the stream, or
processing the contained mapping document.@Deprecated public Configuration addResource(String resourceName, ClassLoader classLoader) throws MappingException
MappingException
public Configuration addResource(String resourceName) throws MappingException
resourceName
- The resource nameMappingException
- Indicates problems locating the resource or
processing the contained mapping document.public Configuration addClass(Class persistentClass) throws MappingException
persistentClass
- The mapped classMappingException
- Indicates problems locating the resource or
processing the contained mapping document.public Configuration addAnnotatedClass(Class annotatedClass)
annotatedClass
- The class containing annotationspublic Configuration addPackage(String packageName) throws MappingException
packageName
- java package nameMappingException
- in case there is an error in the mapping datapublic Configuration addJar(File jar) throws MappingException
jar
- a jar fileMappingException
- Indicates problems reading the jar file or
processing the contained mapping documents.public Configuration addDirectory(File dir) throws MappingException
dir
- The directoryMappingException
- Indicates problems reading the jar file or
processing the contained mapping documents.public Interceptor getInterceptor()
Interceptor
.Interceptor
public Configuration setInterceptor(Interceptor interceptor)
Interceptor
interceptor
- The Interceptor
to use for the built
SessionFactory
.public EntityTuplizerFactory getEntityTuplizerFactory()
public EntityNotFoundDelegate getEntityNotFoundDelegate()
public void setEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate)
entityNotFoundDelegate
- The delegate to usepublic SessionFactoryObserver getSessionFactoryObserver()
public void setSessionFactoryObserver(SessionFactoryObserver sessionFactoryObserver)
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver()
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver)
public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException
SessionFactory
using the properties and mappings in this configuration. The
SessionFactory will be immutable, so changes made to this Configuration after building the
SessionFactory will not affect it.serviceRegistry
- The registry of services to be used in creating this session factory.SessionFactory
HibernateException
- usually indicates an invalid configuration or invalid mapping informationpublic SessionFactory buildSessionFactory() throws HibernateException
SessionFactory
using the properties and mappings in this configuration. The
SessionFactory
will be immutable, so changes made to this
Configuration
after
building the SessionFactory
will not affect it.SessionFactory
HibernateException
- usually indicates an invalid configuration or invalid mapping informationpublic Map<String,SQLFunction> getSqlFunctions()
public void addSqlFunction(String functionName, SQLFunction function)
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object)
public void addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply)
attributeConverterClass
- The AttributeConverter class.autoApply
- Should the AttributeConverter be auto applied to property types as specified
by its "entity attribute" parameterized type?public void addAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass)
attributeConverterClass
- The AttributeConverter class.public void addAttributeConverter(AttributeConverter attributeConverter)
addAttributeConverter(Class, boolean)
formattributeConverter
- The AttributeConverter instance.public void addAttributeConverter(AttributeConverter attributeConverter, boolean autoApply)
addAttributeConverter(Class, boolean)
formattributeConverter
- The AttributeConverter instance.autoApply
- Should the AttributeConverter be auto applied to property types as specified
by its "entity attribute" parameterized type?public void addAttributeConverter(AttributeConverterDefinition definition)
public void setSharedCacheMode(SharedCacheMode sharedCacheMode)
SharedCacheMode.ALL
has
any effect in terms of hbm.xml
binding.sharedCacheMode
- The SharedCacheMode to usepublic Map getNamedSQLQueries()
public Map getSqlResultSetMappings()
public Collection<NamedEntityGraphDefinition> getNamedEntityGraphs()
public Map<String,NamedQueryDefinition> getNamedQueries()
public Map<String,NamedProcedureCallDefinition> getNamedProcedureCallMap()
@Deprecated public void buildMappings()
public Configuration mergeProperties(Properties properties)
properties
- The properties to mergeCopyright © 2017 JBoss by Red Hat. All rights reserved.