public class Configuration extends Object implements Serializable
ServiceRegistryBuilder
and
MetadataSources
instead after the 4.0 release at which point this class will become
deprecated and scheduled for removal in 5.0. See
HHH-6183,
HHH-2578 and
HHH-6586 for detailsSessionFactory
,
Serialized FormModifier and Type | Class and Description |
---|---|
protected class |
Configuration.MappingsImpl
|
protected class |
Configuration.MetadataSourceQueue |
Modifier | Constructor and Description |
---|---|
|
Configuration() |
protected |
Configuration(SettingsFactory settingsFactory) |
Modifier and Type | Method and Description |
---|---|
void |
add(XmlDocument metadataXml) |
Configuration |
addAnnotatedClass(Class annotatedClass)
Read metadata from the annotations associated with this class.
|
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)
Read mappings from a DOM Document
|
void |
addFetchProfile(FetchProfile fetchProfile) |
Configuration |
addFile(File xmlFile)
Read mappings from a particular XML file
|
Configuration |
addFile(String xmlFile)
Read mappings from a particular XML file
|
void |
addFilterDefinition(FilterDefinition definition) |
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 extraProperties)
Add the given properties to ours.
|
Configuration |
addResource(String resourceName)
Read mappings as a application resourceName (i.e.
|
Configuration |
addResource(String resourceName,
ClassLoader classLoader)
Read mappings as a application resource (i.e.
|
void |
addSqlFunction(String functionName,
SQLFunction function) |
Configuration |
addURL(URL url)
Read mappings from a URL
|
Configuration |
addXML(String xml)
Read mappings from a String
|
Mapping |
buildMapping() |
void |
buildMappings()
Call this to ensure the mappings are fully compiled/built.
|
SessionFactory |
buildSessionFactory()
Deprecated.
Use
buildSessionFactory(ServiceRegistry) instead |
SessionFactory |
buildSessionFactory(ServiceRegistry serviceRegistry)
Create a
SessionFactory using the properties and mappings in this configuration. |
Settings |
buildSettings(Properties props,
ServiceRegistry serviceRegistry) |
Settings |
buildSettings(ServiceRegistry serviceRegistry)
Create an object-oriented view of the configuration properties
|
Configuration |
configure()
Use the mappings and properties specified in an application resource named hibernate.cfg.xml.
|
Configuration |
configure(Document document)
Use the mappings and properties specified in the given XML document.
|
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.
|
Mappings |
createMappings()
Create a new Mappings to add class and collection mappings to.
|
protected Configuration |
doConfigure(org.dom4j.Document doc)
Parse a dom4j document conforming to the Hibernate Configuration DTD (hibernate-configuration-3.0.dtd)
and use its information to configure this
Configuration 's state |
protected Configuration |
doConfigure(InputStream stream,
String resourceName)
Configure this configuration's state from the contents of the given input stream.
|
protected ExtendsQueueEntry |
findPossibleExtends() |
String[] |
generateDropSchemaScript(Dialect dialect)
Generate DDL for dropping tables
|
String[] |
generateSchemaCreationScript(Dialect dialect) |
String[] |
generateSchemaUpdateScript(Dialect dialect,
DatabaseMetadata databaseMetadata)
Deprecated.
|
List<SchemaUpdateScript> |
generateSchemaUpdateScriptList(Dialect dialect,
DatabaseMetadata databaseMetadata) |
PersistentClass |
getClassMapping(String entityName)
Get the mapping for a particular entity
|
Iterator<PersistentClass> |
getClassMappings()
Iterate the entity mappings
|
Collection |
getCollectionMapping(String role)
Get the mapping for a particular collection role
|
Iterator |
getCollectionMappings()
Iterate the collection mappings
|
protected InputStream |
getConfigurationInputStream(String resource)
Get the configuration file as an InputStream.
|
CurrentTenantIdentifierResolver |
getCurrentTenantIdentifierResolver() |
EntityNotFoundDelegate |
getEntityNotFoundDelegate()
Retrieve the user-supplied delegate to handle non-existent entity
scenarios.
|
EntityResolver |
getEntityResolver() |
EntityTuplizerFactory |
getEntityTuplizerFactory() |
Map |
getFilterDefinitions() |
MutableIdentifierGeneratorFactory |
getIdentifierGeneratorFactory()
Retrieve the IdentifierGeneratorFactory in effect for this configuration.
|
Map<String,String> |
getImports()
Get the query language imports
|
Interceptor |
getInterceptor()
Retrieve the configured
Interceptor . |
Iterator<MappedSuperclass> |
getMappedSuperclassMappings()
Iterate the mapped super class mappings
EXPERIMENTAL Consider this API as PRIVATE
|
Map<String,NamedQueryDefinition> |
getNamedQueries() |
Map |
getNamedSQLQueries() |
NamingStrategy |
getNamingStrategy() |
NamingStrategyDelegator |
getNamingStrategyDelegator() |
Properties |
getProperties()
Get all properties
|
String |
getProperty(String propertyName)
Get a property value by name
|
ReflectionManager |
getReflectionManager() |
SessionFactoryObserver |
getSessionFactoryObserver() |
Map |
getSqlFunctions() |
Map |
getSqlResultSetMappings() |
Iterator<Table> |
getTableMappings()
Iterate the table mappings
|
TypeResolver |
getTypeResolver() |
Iterator |
iterateFetchProfiles() |
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.
|
void |
registerTypeContributor(TypeContributor typeContributor) |
void |
registerTypeOverride(BasicType type)
Allows registration of a type into the type registry.
|
void |
registerTypeOverride(CompositeUserType type,
String[] keys) |
void |
registerTypeOverride(UserType type,
String[] keys) |
protected void |
reset() |
protected void |
secondPassCompile() |
protected void |
secondPassCompileForeignKeys(Table table,
Set<ForeignKey> done) |
Configuration |
setCacheConcurrencyStrategy(String entityName,
String concurrencyStrategy)
Set up a cache for an entity class
|
Configuration |
setCacheConcurrencyStrategy(String entityName,
String concurrencyStrategy,
String region)
Set up a cache for an entity class, giving an explicit region name
|
void |
setCacheConcurrencyStrategy(String entityName,
String concurrencyStrategy,
String region,
boolean cacheLazyProperty) |
Configuration |
setCollectionCacheConcurrencyStrategy(String collectionRole,
String concurrencyStrategy)
Set up a cache for a collection role
|
void |
setCollectionCacheConcurrencyStrategy(String collectionRole,
String concurrencyStrategy,
String region)
Set up a cache for a collection role, giving an explicit region name
|
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 |
setEntityResolver(EntityResolver entityResolver)
Set a custom entity resolver.
|
Configuration |
setInterceptor(Interceptor interceptor)
Set the current
Interceptor |
Configuration |
setNamingStrategy(NamingStrategy namingStrategy)
Set the current naming strategy.
|
Configuration |
setNamingStrategyDelegator(NamingStrategyDelegator namingStrategyDelegator)
Set a current naming strategy delegator.
|
void |
setPrecedence(String precedence) |
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 |
validateSchema(Dialect dialect,
DatabaseMetadata databaseMetadata) |
public static final String DEFAULT_CACHE_CONCURRENCY_STRATEGY
public static final String USE_NEW_ID_GENERATOR_MAPPINGS
public static final String ARTEFACT_PROCESSING_ORDER
protected Configuration.MetadataSourceQueue metadataSourceQueue
protected Map<String,PersistentClass> classes
protected Map<String,Collection> collections
protected List<AuxiliaryDatabaseObject> auxiliaryDatabaseObjects
protected Map<String,NamedQueryDefinition> namedQueries
protected Map<String,NamedSQLQueryDefinition> namedSqlQueries
protected Map<String,ResultSetMappingDefinition> sqlResultSetMappings
protected Map<String,FilterDefinition> filterDefinitions
protected Map<String,FetchProfile> fetchProfiles
protected Map tableNameBinding
protected Map columnNameBindingPerTable
protected List<SecondPass> secondPasses
protected List<Mappings.PropertyReference> propertyReferences
protected Map<ExtendsQueueEntry,?> extendsQueue
protected Map<String,SQLFunction> sqlFunctions
protected transient XMLHelper xmlHelper
protected final SettingsFactory settingsFactory
public static final MetadataSourceType[] DEFAULT_ARTEFACT_PROCESSING_ORDER
protected Configuration(SettingsFactory settingsFactory)
public Configuration()
protected void reset()
public EntityTuplizerFactory getEntityTuplizerFactory()
public ReflectionManager getReflectionManager()
public Iterator<PersistentClass> getClassMappings()
public Iterator getCollectionMappings()
public Iterator<Table> getTableMappings()
public Iterator<MappedSuperclass> getMappedSuperclassMappings()
public PersistentClass getClassMapping(String entityName)
entityName
- An entity name.public Collection getCollectionMapping(String role)
role
- a collection rolepublic void setEntityResolver(EntityResolver entityResolver)
DTDEntityResolver
entityResolver
- entity resolver to usepublic EntityResolver getEntityResolver()
public EntityNotFoundDelegate getEntityNotFoundDelegate()
public void setEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate)
entityNotFoundDelegate
- The delegate to usepublic 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. Historically this could
have indicated a problem parsing the XML document, but that is now delayed until after buildMappings()
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)
public Configuration addXML(String xml) throws MappingException
xml
- an XML stringMappingException
- Indicates problems parsing the
given XML stringpublic 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.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.public Configuration addResource(String resourceName, ClassLoader classLoader) throws MappingException
resourceName
- The resource nameclassLoader
- The class loader to use.MappingException
- Indicates problems locating the resource or
processing the contained mapping document.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 Mappings createMappings()
public String[] generateDropSchemaScript(Dialect dialect) throws HibernateException
dialect
- The dialect for which to generate the drop scriptHibernateException
- Generally indicates a problem calling buildMappings()
SchemaExport
public String[] generateSchemaCreationScript(Dialect dialect) throws HibernateException
dialect
- The dialect for which to generate the creation scriptHibernateException
- Generally indicates a problem calling buildMappings()
SchemaExport
@Deprecated public String[] generateSchemaUpdateScript(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException
generateSchemaUpdateScriptList(Dialect, DatabaseMetadata)
insteaddialect
- The dialect for which to generate the creation scriptdatabaseMetadata
- The database catalog information for the database to be updated; needed to work out what
should be created/alteredHibernateException
- Generally indicates a problem calling buildMappings()
SchemaUpdate
public List<SchemaUpdateScript> generateSchemaUpdateScriptList(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException
dialect
- The dialect for which to generate the creation scriptdatabaseMetadata
- The database catalog information for the database to be updated; needed to work out what
should be created/alteredHibernateException
- Generally indicates a problem calling buildMappings()
SchemaUpdate
public void validateSchema(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException
HibernateException
public void buildMappings()
protected void secondPassCompile() throws MappingException
MappingException
protected ExtendsQueueEntry findPossibleExtends()
protected void secondPassCompileForeignKeys(Table table, Set<ForeignKey> done) throws MappingException
MappingException
public Map<String,NamedQueryDefinition> getNamedQueries()
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
buildSessionFactory(ServiceRegistry)
insteadSessionFactory
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 Interceptor getInterceptor()
Interceptor
.Interceptor
public Configuration setInterceptor(Interceptor interceptor)
Interceptor
interceptor
- The Interceptor
to use for the built
SessionFactory
.public Properties getProperties()
public String getProperty(String propertyName)
propertyName
- The name of the propertypublic Configuration setProperties(Properties properties)
properties
- The new set of propertiespublic Configuration addProperties(Properties extraProperties)
extraProperties
- The properties to add.public Configuration mergeProperties(Properties properties)
properties
- The properties to mergepublic Configuration setProperty(String propertyName, String value)
propertyName
- The name of the property to setvalue
- The new property valuepublic Configuration configure() throws HibernateException
HibernateException
- Generally indicates we cannot find hibernate.cfg.xmlconfigure(String)
public Configuration configure(String resource) throws HibernateException
getConfigurationInputStream(java.lang.String)
resource
- The resource to useHibernateException
- Generally indicates we cannot find the named resourcedoConfigure(java.io.InputStream, String)
protected InputStream getConfigurationInputStream(String resource) throws HibernateException
resource
- The resource to locateHibernateException
- Generally indicates we cannot find the named resourcepublic Configuration configure(URL url) throws HibernateException
url
- URL from which you wish to load the configurationHibernateException
- Generally indicates a problem access the urldoConfigure(java.io.InputStream, String)
public Configuration configure(File configFile) throws HibernateException
configFile
- File from which you wish to load the configurationHibernateException
- Generally indicates a problem access the filedoConfigure(java.io.InputStream, String)
protected Configuration doConfigure(InputStream stream, String resourceName) throws HibernateException
doConfigure(Document)
for further details.stream
- The input stream from which to readresourceName
- The name to use in warning/error messagesHibernateException
- Indicates a problem reading the stream contents.public Configuration configure(Document document) throws HibernateException
document
- an XML document from which you wish to load the configurationHibernateException
- if there is problem in accessing the file.protected Configuration doConfigure(org.dom4j.Document doc) throws HibernateException
Configuration
's statedoc
- The dom4j documentHibernateException
- Indicates a problem performing the configuration taskpublic Configuration setCacheConcurrencyStrategy(String entityName, String concurrencyStrategy)
entityName
- The name of the entity to which we shoudl associate these cache settingsconcurrencyStrategy
- The cache strategy to usepublic Configuration setCacheConcurrencyStrategy(String entityName, String concurrencyStrategy, String region)
entityName
- The name of the entity to which we should associate these cache settingsconcurrencyStrategy
- The cache strategy to useregion
- The name of the cache region to usepublic void setCacheConcurrencyStrategy(String entityName, String concurrencyStrategy, String region, boolean cacheLazyProperty) throws MappingException
MappingException
public Configuration setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy)
collectionRole
- The name of the collection to which we should associate these cache settingsconcurrencyStrategy
- The cache strategy to usepublic void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String region)
collectionRole
- The name of the collection to which we should associate these cache settingsconcurrencyStrategy
- The cache strategy to useregion
- The name of the cache region to usepublic Map<String,String> getImports()
public Settings buildSettings(ServiceRegistry serviceRegistry)
serviceRegistry
- The registry of services to be used in building these settings.public Settings buildSettings(Properties props, ServiceRegistry serviceRegistry) throws HibernateException
HibernateException
public Map getNamedSQLQueries()
public Map getSqlResultSetMappings()
public NamingStrategy getNamingStrategy()
public NamingStrategyDelegator getNamingStrategyDelegator()
public Configuration setNamingStrategy(NamingStrategy namingStrategy)
LegacyNamingStrategyDelegator
will be constructed with the specified naming strategy.namingStrategy
- the NamingStrategy
to set; must be non-null.LegacyNamingStrategyDelegator.LegacyNamingStrategyDelegator(NamingStrategy)
public Configuration setNamingStrategyDelegator(NamingStrategyDelegator namingStrategyDelegator)
namingStrategyDelegator
- the NamingStrategyDelegator
to set;
must be non-null; if namingStrategyDelegator
is an instance
of LegacyNamingStrategyDelegator
, then
LegacyNamingStrategyDelegator.getNamingStrategy()
must be non-null.MappingException
- if namingStrategyDelegator
is null.MappingException
- if namingStrategyDelegator
is an instance
of LegacyNamingStrategyDelegator
and LegacyNamingStrategyDelegator.getNamingStrategy()
is null.public MutableIdentifierGeneratorFactory getIdentifierGeneratorFactory()
public Mapping buildMapping()
public Map getFilterDefinitions()
public void addFilterDefinition(FilterDefinition definition)
public Iterator iterateFetchProfiles()
public void addFetchProfile(FetchProfile fetchProfile)
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object)
public Map getSqlFunctions()
public void addSqlFunction(String functionName, SQLFunction function)
public TypeResolver getTypeResolver()
public void registerTypeOverride(BasicType type)
type
- The type to register.public void registerTypeOverride(CompositeUserType type, String[] keys)
public void registerTypeContributor(TypeContributor typeContributor)
public SessionFactoryObserver getSessionFactoryObserver()
public void setSessionFactoryObserver(SessionFactoryObserver sessionFactoryObserver)
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver()
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver)
public void setPrecedence(String precedence)
Copyright © 2018 JBoss by Red Hat. All rights reserved.