|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.hibernate.cfg.Configuration
public class Configuration
An instance of Configuration allows the application
to specify properties and mapping documents to be used when
creating a SessionFactory. Usually an application will create
a single Configuration, build a single instance of
SessionFactory and then instantiate Sessions in
threads servicing client requests. The Configuration is meant
only as an initialization-time object. SessionFactorys are
immutable and do not retain any association back to the
Configuration.
A new Configuration will use the properties specified in
hibernate.properties by default.
SessionFactory
,
Serialized FormNested Class Summary | |
---|---|
protected class |
Configuration.MappingsImpl
Internal implementation of the Mappings interface giving access to the Configuration's internal metadata repository state ( classes , tables , etc). |
protected class |
Configuration.MetadataSourceQueue
|
Constructor Summary | |
---|---|
|
Configuration()
|
protected |
Configuration(SettingsFactory settingsFactory)
|
Method Summary | |
---|---|
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()
Create a SessionFactory using the properties and mappings in this configuration. |
Settings |
buildSettings()
Create an object-oriented view of the configuration properties |
Settings |
buildSettings(Properties props)
|
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)
|
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. |
EntityNotFoundDelegate |
getEntityNotFoundDelegate()
Retrieve the user-supplied delegate to handle non-existent entity scenarios. |
EntityResolver |
getEntityResolver()
|
EntityTuplizerFactory |
getEntityTuplizerFactory()
|
EventListeners |
getEventListeners()
|
Map |
getFilterDefinitions()
|
DefaultIdentifierGeneratorFactory |
getIdentifierGeneratorFactory()
Retrieve the IdentifierGeneratorFactory in effect for this configuration. |
Map<String,String> |
getImports()
Get the query language imports |
Interceptor |
getInterceptor()
Rterieve 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()
|
PersisterClassProvider |
getPersisterClassProvider()
|
Properties |
getProperties()
Get all properties |
String |
getProperty(String propertyName)
Get a property value by name |
org.hibernate.annotations.common.reflection.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 |
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 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 |
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 |
void |
setListener(String type,
Object listener)
|
void |
setListener(String type,
String listener)
|
void |
setListeners(String type,
Object[] listeners)
|
void |
setListeners(String type,
String[] listenerClasses)
|
Configuration |
setNamingStrategy(NamingStrategy namingStrategy)
Set a custom naming strategy |
Configuration |
setPersisterClassProvider(PersisterClassProvider persisterClassProvider)
Defines a custom persister class provider. |
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)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_CACHE_CONCURRENCY_STRATEGY
CacheConcurrencyStrategy
to use when either @Cacheable
or
@Cache
is used. @Cache(strategy="..")
is used to override.
public static final String USE_NEW_ID_GENERATOR_MAPPINGS
IdentifierGenerator
are used
for AUTO, TABLE and SEQUENCE.
Default to false to keep backward compatibility.
public static final String ARTEFACT_PROCESSING_ORDER
protected Configuration.MetadataSourceQueue metadataSourceQueue
protected Map<String,PersistentClass> classes
protected Map<String,String> imports
protected Map<String,Collection> collections
protected Map<String,Table> tables
protected List<AuxiliaryDatabaseObject> auxiliaryDatabaseObjects
protected Map<String,NamedQueryDefinition> namedQueries
protected Map<String,NamedSQLQueryDefinition> namedSqlQueries
protected Map<String,ResultSetMappingDefinition> sqlResultSetMappings
protected Map<String,TypeDef> typeDefs
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 NamingStrategy namingStrategy
protected final SettingsFactory settingsFactory
public static final MetadataSourceType[] DEFAULT_ARTEFACT_PROCESSING_ORDER
Constructor Detail |
---|
protected Configuration(SettingsFactory settingsFactory)
public Configuration()
Method Detail |
---|
protected void reset()
public EntityTuplizerFactory getEntityTuplizerFactory()
public org.hibernate.annotations.common.reflection.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 role
public 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 file
MappingException
- 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 file
MappingException
- 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 reason
xmlFile
- The xml file, not the bin!
SerializationException
- Indicates a problem deserializing the cached dom tree
FileNotFoundException
- 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 string
MappingException
- 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 document
MappingException
- 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 name
MappingException
- Indicates problems locating the resource or
processing the contained mapping document.public Configuration addClass(Class persistentClass) throws MappingException
persistentClass
- The mapped class
MappingException
- Indicates problems locating the resource or
processing the contained mapping document.public Configuration addAnnotatedClass(Class annotatedClass)
annotatedClass
- The class containing annotations
public Configuration addPackage(String packageName) throws MappingException
packageName
- java package name
MappingException
- in case there is an error in the mapping datapublic Configuration addJar(File jar) throws MappingException
jar
- a jar file
MappingException
- Indicates problems reading the jar file or
processing the contained mapping documents.public Configuration addDirectory(File dir) throws MappingException
dir
- The directory
MappingException
- 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 script
HibernateException
- Generally indicates a problem calling buildMappings()
SchemaExport
public String[] generateSchemaCreationScript(Dialect dialect) throws HibernateException
dialect
- The dialect for which to generate the creation script
HibernateException
- Generally indicates a problem calling buildMappings()
SchemaExport
public String[] generateSchemaUpdateScript(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/altered
HibernateException
- Generally indicates a problem calling buildMappings()
SchemaExport
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 done) throws MappingException
MappingException
public Map<String,NamedQueryDefinition> getNamedQueries()
public 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 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 property
public Configuration setProperties(Properties properties)
properties
- The new set of properties
public Configuration addProperties(Properties extraProperties)
extraProperties
- The properties to add.
public Configuration mergeProperties(Properties properties)
properties
- The properties to merge
public Configuration setProperty(String propertyName, String value)
propertyName
- The name of the property to setvalue
- The new property value
public 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 use
HibernateException
- Generally indicates we cannot find the named resourcedoConfigure(java.io.InputStream, String)
protected InputStream getConfigurationInputStream(String resource) throws HibernateException
resource
- The resource to locate
HibernateException
- Generally indicates we cannot find the named resourcepublic Configuration configure(URL url) throws HibernateException
url
- URL from which you wish to load the configuration
HibernateException
- 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 configuration
HibernateException
- 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 messages
HibernateException
- 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 configuration
HibernateException
- if there is problem in accessing the file.protected Configuration doConfigure(org.dom4j.Document doc) throws HibernateException
Configuration
's state
doc
- The dom4j document
HibernateException
- Indicates a problem performing the configuration taskpublic void setListener(String type, String listener)
public void setListeners(String type, String[] listenerClasses)
public void setListener(String type, Object listener)
public void setListeners(String type, Object[] listeners)
public EventListeners getEventListeners()
public Configuration setCacheConcurrencyStrategy(String entityName, String concurrencyStrategy)
entityName
- The name of the entity to which we shoudl associate these cache settingsconcurrencyStrategy
- The cache strategy to use
public 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 use
public 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 use
public 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()
public Settings buildSettings(Properties props) throws HibernateException
HibernateException
public Map getNamedSQLQueries()
public Map getSqlResultSetMappings()
public NamingStrategy getNamingStrategy()
public Configuration setNamingStrategy(NamingStrategy namingStrategy)
namingStrategy
- the NamingStrategy to set
public PersisterClassProvider getPersisterClassProvider()
public Configuration setPersisterClassProvider(PersisterClassProvider persisterClassProvider)
persisterClassProvider
- implementationpublic DefaultIdentifierGeneratorFactory 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(UserType type, String[] keys)
public void registerTypeOverride(CompositeUserType type, String[] keys)
public SessionFactoryObserver getSessionFactoryObserver()
public void setSessionFactoryObserver(SessionFactoryObserver sessionFactoryObserver)
public void setPrecedence(String precedence)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |