org.hibernate.cfg
Class AnnotationConfiguration

java.lang.Object
  extended by org.hibernate.cfg.Configuration
      extended by org.hibernate.cfg.AnnotationConfiguration
All Implemented Interfaces:
Serializable

public class AnnotationConfiguration
extends Configuration

Similar to the Configuration object but handles EJB3 and Hibernate specific annotations as a metadata facility.

Author:
Emmanuel Bernard, Hardy Ferentschik
See Also:
Serialized Form

Nested Class Summary
protected  class AnnotationConfiguration.ExtendedMappingsImpl
           
 
Nested classes/interfaces inherited from class org.hibernate.cfg.Configuration
Configuration.MappingsImpl
 
Field Summary
static String ARTEFACT_PROCESSING_ORDER
           
static ConfigurationArtefactType[] DEFAULT_ARTEFACT_PROCESSING_ORDER
           
static String DEFAULT_CACHE_CONCURRENCY_STRATEGY
          Setting used to give the name of the default CacheConcurrencyStrategy to use when either @Cacheable or @Cache is used.
static String USE_NEW_ID_GENERATOR_MAPPINGS
          Setting which indicates whether or not the new IdentifierGenerator are used for AUTO, TABLE and SEQUENCE.
 
Fields inherited from class org.hibernate.cfg.Configuration
auxiliaryDatabaseObjects, classes, collections, columnNameBindingPerTable, extendsQueue, fetchProfiles, filterDefinitions, imports, namedQueries, namedSqlQueries, namingStrategy, propertyReferences, secondPasses, settingsFactory, sqlFunctions, sqlResultSetMappings, tableNameBinding, tables, typeDefs, xmlHelper
 
Constructor Summary
AnnotationConfiguration()
           
AnnotationConfiguration(SettingsFactory sf)
           
 
Method Summary
 void add(org.dom4j.Document doc)
           
 AnnotationConfiguration addAnnotatedClass(Class persistentClass)
          Read a mapping from the class annotation metadata (JSR 175).
 AnnotationConfiguration addCacheableFile(File xmlFile)
          Add a cached mapping file.
 AnnotationConfiguration addCacheableFile(String xmlFile)
          Add a cacheable mapping file.
 AnnotationConfiguration addClass(Class persistentClass)
          Read a mapping as an application resouurce 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.
 AnnotationConfiguration addDirectory(File dir)
          Read all mapping documents from a directory tree.
 AnnotationConfiguration addDocument(Document doc)
          Read mappings from a DOM Document
 AnnotationConfiguration addFile(File xmlFile)
          Read mappings from a particular XML file
 AnnotationConfiguration addFile(String xmlFile)
          Read mappings from a particular XML file
 AnnotationConfiguration addInputStream(InputStream xmlInputStream)
          Read mappings from an InputStream.
 AnnotationConfiguration addJar(File jar)
          Read all mappings from a jar file

Assumes that any file named *.hbm.xml is a mapping document.

 AnnotationConfiguration addPackage(String packageName)
          Read package level metadata.
 AnnotationConfiguration addProperties(Properties extraProperties)
          Set the given properties
 AnnotationConfiguration addResource(String resourceName)
          Read mappings as a application resourceName (i.e.
 AnnotationConfiguration addResource(String resourceName, ClassLoader classLoader)
          Read mappings as a application resource (i.e.
 AnnotationConfiguration addURL(URL url)
          Read mappings from a URL
 AnnotationConfiguration addXML(String xml)
          Read mappings from a String
 SessionFactory buildSessionFactory()
          Instantiate a new SessionFactory, using the properties and mappings in this configuration.
 AnnotationConfiguration configure()
          Use the mappings and properties specified in an application resource named hibernate.cfg.xml.
 AnnotationConfiguration configure(Document document)
          Use the mappings and properties specified in the given XML document.
 AnnotationConfiguration configure(File configFile)
          Use the mappings and properties specified in the given application file.
 AnnotationConfiguration configure(String resource)
          Use the mappings and properties specified in the given application resource.
 AnnotationConfiguration configure(URL url)
          Use the mappings and properties specified in the given document.
 ExtendedMappings createExtendedMappings()
           
protected  AnnotationConfiguration doConfigure(org.dom4j.Document doc)
           
protected  AnnotationConfiguration doConfigure(InputStream stream, String resourceName)
          Use the mappings and properties specified in the given application resource.
 org.hibernate.annotations.common.reflection.ReflectionManager getReflectionManager()
           
 AnnotationConfiguration mergeProperties(Properties properties)
          Adds the incoming properties to the internap properties structure, as long as the internal structure does not already contain an entry for the given key.
protected  List<org.hibernate.annotations.common.reflection.XClass> orderAndFillHierarchy(List<org.hibernate.annotations.common.reflection.XClass> original)
          Takes the list of entities annotated with @Entity or @MappedSuperclass and returns them in an ordered list.
protected  void parseMappingElement(org.dom4j.Element subelement, String name)
           
protected  void reset()
           
protected  void secondPassCompile()
           
 AnnotationConfiguration setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy)
          Set up a cache for an entity class
 void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String region, boolean cacheLazyProperty)
           
 AnnotationConfiguration setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy)
          Set up a cache for a collection role
 void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String region)
           
 AnnotationConfiguration setInterceptor(Interceptor interceptor)
          Configure an Interceptor
 AnnotationConfiguration setNamingStrategy(NamingStrategy namingStrategy)
          Set a custom naming strategy
 void setPrecedence(String precedence)
           
 AnnotationConfiguration setProperties(Properties properties)
          Specify a completely new set of properties
 AnnotationConfiguration setProperty(String propertyName, String value)
          Set a property
 
Methods inherited from class org.hibernate.cfg.Configuration
addAuxiliaryDatabaseObject, addCacheableFileStrictly, addFetchProfile, addFilterDefinition, addSqlFunction, buildMapping, buildMappings, buildSettings, buildSettings, createMappings, findPossibleExtends, generateDropSchemaScript, generateSchemaCreationScript, generateSchemaUpdateScript, getClassMapping, getClassMappings, getCollectionMapping, getCollectionMappings, getConfigurationInputStream, getEntityNotFoundDelegate, getEntityResolver, getEntityTuplizerFactory, getEventListeners, getFilterDefinitions, getIdentifierGeneratorFactory, getImports, getInterceptor, getMappedSuperclassMappings, getNamedQueries, getNamedSQLQueries, getNamingStrategy, getProperties, getProperty, getSessionFactoryObserver, getSqlFunctions, getSqlResultSetMappings, getTableMappings, iterateFetchProfiles, secondPassCompileForeignKeys, setCacheConcurrencyStrategy, setEntityNotFoundDelegate, setEntityResolver, setListener, setListener, setListeners, setListeners, setSessionFactoryObserver, validateSchema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CACHE_CONCURRENCY_STRATEGY

public static final String DEFAULT_CACHE_CONCURRENCY_STRATEGY
Setting used to give the name of the default CacheConcurrencyStrategy to use when either @Cacheable or @Cache is used. @Cache(strategy="..") is used to override.

See Also:
Constant Field Values

USE_NEW_ID_GENERATOR_MAPPINGS

public static final String USE_NEW_ID_GENERATOR_MAPPINGS
Setting which indicates whether or not the new IdentifierGenerator are used for AUTO, TABLE and SEQUENCE. Default to false to keep backward compatibility.

See Also:
Constant Field Values

ARTEFACT_PROCESSING_ORDER

public static final String ARTEFACT_PROCESSING_ORDER
See Also:
Constant Field Values

DEFAULT_ARTEFACT_PROCESSING_ORDER

public static final ConfigurationArtefactType[] DEFAULT_ARTEFACT_PROCESSING_ORDER
Constructor Detail

AnnotationConfiguration

public AnnotationConfiguration()

AnnotationConfiguration

public AnnotationConfiguration(SettingsFactory sf)
Method Detail

orderAndFillHierarchy

protected List<org.hibernate.annotations.common.reflection.XClass> orderAndFillHierarchy(List<org.hibernate.annotations.common.reflection.XClass> original)
Takes the list of entities annotated with @Entity or @MappedSuperclass and returns them in an ordered list.

Parameters:
original - The list of all entities annotated with @Entity or @MappedSuperclass
Returns:
Ordered list of entities including superclasses for entities which have any. Class hierachies are listed bottom up (starting from the top level base class). There is no indication in the list when a new class (hierarchy) starts.

addAnnotatedClass

public AnnotationConfiguration addAnnotatedClass(Class persistentClass)
                                          throws MappingException
Read a mapping from the class annotation metadata (JSR 175).

Parameters:
persistentClass - the mapped class
Returns:
the configuration object
Throws:
MappingException - in case there is a configuration error for the specified class

addPackage

public AnnotationConfiguration addPackage(String packageName)
                                   throws MappingException
Read package level metadata.

Parameters:
packageName - java package name
Returns:
the configuration object
Throws:
MappingException - in case there is an error in the mapping data

createExtendedMappings

public ExtendedMappings createExtendedMappings()

setCacheConcurrencyStrategy

public void setCacheConcurrencyStrategy(String clazz,
                                        String concurrencyStrategy,
                                        String region,
                                        boolean cacheLazyProperty)
                                 throws MappingException
Throws:
MappingException

setCollectionCacheConcurrencyStrategy

public void setCollectionCacheConcurrencyStrategy(String collectionRole,
                                                  String concurrencyStrategy,
                                                  String region)
                                           throws MappingException
Overrides:
setCollectionCacheConcurrencyStrategy in class Configuration
Throws:
MappingException

reset

protected void reset()
Overrides:
reset in class Configuration

secondPassCompile

protected void secondPassCompile()
                          throws MappingException
Overrides:
secondPassCompile in class Configuration
Throws:
MappingException

parseMappingElement

protected void parseMappingElement(org.dom4j.Element subelement,
                                   String name)
Overrides:
parseMappingElement in class Configuration

add

public void add(org.dom4j.Document doc)
         throws MappingException
Overrides:
add in class Configuration
Throws:
MappingException

setPrecedence

public void setPrecedence(String precedence)

addInputStream

public AnnotationConfiguration addInputStream(InputStream xmlInputStream)
                                       throws MappingException
Description copied from class: Configuration
Read mappings from an InputStream.

Overrides:
addInputStream in class Configuration
Parameters:
xmlInputStream - The input stream containing a DOM.
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems reading the stream, or processing the contained mapping document.

buildSessionFactory

public SessionFactory buildSessionFactory()
                                   throws HibernateException
Description copied from class: Configuration
Instantiate a new SessionFactory, using the properties and mappings in this configuration. The SessionFactory will be immutable, so changes made to the Configuration after building the SessionFactory will not affect it.

Overrides:
buildSessionFactory in class Configuration
Returns:
a new factory for Sessions
Throws:
HibernateException
See Also:
SessionFactory

addFile

public AnnotationConfiguration addFile(String xmlFile)
                                throws MappingException
Description copied from class: Configuration
Read mappings from a particular XML file

Overrides:
addFile in class Configuration
Parameters:
xmlFile - a path to a file
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates inability to locate or parse the specified mapping file.
See Also:
Configuration.addFile(java.io.File)

addFile

public AnnotationConfiguration addFile(File xmlFile)
                                throws MappingException
Description copied from class: Configuration
Read mappings from a particular XML file

Overrides:
addFile in class Configuration
Parameters:
xmlFile - a path to a file
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates inability to locate or parse the specified mapping file.

addCacheableFile

public AnnotationConfiguration addCacheableFile(File xmlFile)
                                         throws MappingException
Description copied from class: Configuration
Add a cached mapping file. A cached file is a serialized representation of the DOM structure of a particular mapping. It is saved from a previous call as a file with the name xmlFile + ".bin" where xmlFile is the name of the original mapping file.

If a cached xmlFile + ".bin" exists and is newer than xmlFile the ".bin" file will be read directly. Otherwise xmlFile is read and then serialized to xmlFile + ".bin" for use the next time.

Overrides:
addCacheableFile in class Configuration
Parameters:
xmlFile - The cacheable mapping file to be added.
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems reading the cached file or processing the non-cached file.

addCacheableFile

public AnnotationConfiguration addCacheableFile(String xmlFile)
                                         throws MappingException
Description copied from class: Configuration
Add a cacheable mapping file.

Overrides:
addCacheableFile in class Configuration
Parameters:
xmlFile - The name of the file to be added. This must be in a form useable to simply construct a File instance.
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems reading the cached file or processing the non-cached file.
See Also:
Configuration.addCacheableFile(java.io.File)

addXML

public AnnotationConfiguration addXML(String xml)
                               throws MappingException
Description copied from class: Configuration
Read mappings from a String

Overrides:
addXML in class Configuration
Parameters:
xml - an XML string
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems parsing the given XML string

addURL

public AnnotationConfiguration addURL(URL url)
                               throws MappingException
Description copied from class: Configuration
Read mappings from a URL

Overrides:
addURL in class Configuration
Parameters:
url - The url for the mapping document to be read.
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems reading the URL or processing the mapping document.

addResource

public AnnotationConfiguration addResource(String resourceName,
                                           ClassLoader classLoader)
                                    throws MappingException
Description copied from class: Configuration
Read mappings as a application resource (i.e. classpath lookup).

Overrides:
addResource in class Configuration
Parameters:
resourceName - The resource name
classLoader - The class loader to use.
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems locating the resource or processing the contained mapping document.

addDocument

public AnnotationConfiguration addDocument(Document doc)
                                    throws MappingException
Description copied from class: Configuration
Read mappings from a DOM Document

Overrides:
addDocument in class Configuration
Parameters:
doc - The DOM document
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems reading the DOM or processing the mapping document.

addResource

public AnnotationConfiguration addResource(String resourceName)
                                    throws MappingException
Description copied from class: Configuration
Read mappings as a application resourceName (i.e. classpath lookup) trying different classloaders.

Overrides:
addResource in class Configuration
Parameters:
resourceName - The resource name
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems locating the resource or processing the contained mapping document.

addClass

public AnnotationConfiguration addClass(Class persistentClass)
                                 throws MappingException
Description copied from class: Configuration
Read a mapping as an application resouurce 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.

Overrides:
addClass in class Configuration
Parameters:
persistentClass - The mapped class
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems locating the resource or processing the contained mapping document.

addJar

public AnnotationConfiguration addJar(File jar)
                               throws MappingException
Description copied from class: Configuration
Read all mappings from a jar file

Assumes that any file named *.hbm.xml is a mapping document.

Overrides:
addJar in class Configuration
Parameters:
jar - a jar file
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems reading the jar file or processing the contained mapping documents.

addDirectory

public AnnotationConfiguration addDirectory(File dir)
                                     throws MappingException
Description copied from class: Configuration
Read all mapping documents from a directory tree.

Assumes that any file named *.hbm.xml is a mapping document.

Overrides:
addDirectory in class Configuration
Parameters:
dir - The directory
Returns:
this (for method chaining purposes)
Throws:
MappingException - Indicates problems reading the jar file or processing the contained mapping documents.

setInterceptor

public AnnotationConfiguration setInterceptor(Interceptor interceptor)
Description copied from class: Configuration
Configure an Interceptor

Overrides:
setInterceptor in class Configuration

setProperties

public AnnotationConfiguration setProperties(Properties properties)
Description copied from class: Configuration
Specify a completely new set of properties

Overrides:
setProperties in class Configuration

addProperties

public AnnotationConfiguration addProperties(Properties extraProperties)
Description copied from class: Configuration
Set the given properties

Overrides:
addProperties in class Configuration

mergeProperties

public AnnotationConfiguration mergeProperties(Properties properties)
Description copied from class: Configuration
Adds the incoming properties to the internap properties structure, as long as the internal structure does not already contain an entry for the given key.

Overrides:
mergeProperties in class Configuration
Returns:
this

setProperty

public AnnotationConfiguration setProperty(String propertyName,
                                           String value)
Description copied from class: Configuration
Set a property

Overrides:
setProperty in class Configuration

configure

public AnnotationConfiguration configure()
                                  throws HibernateException
Description copied from class: Configuration
Use the mappings and properties specified in an application resource named hibernate.cfg.xml.

Overrides:
configure in class Configuration
Throws:
HibernateException

configure

public AnnotationConfiguration configure(String resource)
                                  throws HibernateException
Description copied from class: Configuration
Use the mappings and properties specified in the given application resource. The format of the resource is defined in hibernate-configuration-3.0.dtd.

The resource is found via getConfigurationInputStream(resource).

Overrides:
configure in class Configuration
Throws:
HibernateException

configure

public AnnotationConfiguration configure(URL url)
                                  throws HibernateException
Description copied from class: Configuration
Use the mappings and properties specified in the given document. The format of the document is defined in hibernate-configuration-3.0.dtd.

Overrides:
configure in class Configuration
Parameters:
url - URL from which you wish to load the configuration
Returns:
A configuration configured via the file
Throws:
HibernateException

configure

public AnnotationConfiguration configure(File configFile)
                                  throws HibernateException
Description copied from class: Configuration
Use the mappings and properties specified in the given application file. The format of the file is defined in hibernate-configuration-3.0.dtd.

Overrides:
configure in class Configuration
Parameters:
configFile - File from which you wish to load the configuration
Returns:
A configuration configured via the file
Throws:
HibernateException

doConfigure

protected AnnotationConfiguration doConfigure(InputStream stream,
                                              String resourceName)
                                       throws HibernateException
Description copied from class: Configuration
Use the mappings and properties specified in the given application resource. The format of the resource is defined in hibernate-configuration-3.0.dtd.

Overrides:
doConfigure in class Configuration
Parameters:
stream - Inputstream to be read from
resourceName - The name to use in warning/error messages
Returns:
A configuration configured via the stream
Throws:
HibernateException

configure

public AnnotationConfiguration configure(Document document)
                                  throws HibernateException
Description copied from class: Configuration
Use the mappings and properties specified in the given XML document. The format of the file is defined in hibernate-configuration-3.0.dtd.

Overrides:
configure in class Configuration
Parameters:
document - an XML document from which you wish to load the configuration
Returns:
A configuration configured via the Document
Throws:
HibernateException - if there is problem in accessing the file.

doConfigure

protected AnnotationConfiguration doConfigure(org.dom4j.Document doc)
                                       throws HibernateException
Overrides:
doConfigure in class Configuration
Throws:
HibernateException

setCacheConcurrencyStrategy

public AnnotationConfiguration setCacheConcurrencyStrategy(String clazz,
                                                           String concurrencyStrategy)
                                                    throws MappingException
Description copied from class: Configuration
Set up a cache for an entity class

Overrides:
setCacheConcurrencyStrategy in class Configuration
Returns:
Configuration
Throws:
MappingException

setCollectionCacheConcurrencyStrategy

public AnnotationConfiguration setCollectionCacheConcurrencyStrategy(String collectionRole,
                                                                     String concurrencyStrategy)
                                                              throws MappingException
Description copied from class: Configuration
Set up a cache for a collection role

Overrides:
setCollectionCacheConcurrencyStrategy in class Configuration
Returns:
Configuration
Throws:
MappingException

setNamingStrategy

public AnnotationConfiguration setNamingStrategy(NamingStrategy namingStrategy)
Description copied from class: Configuration
Set a custom naming strategy

Overrides:
setNamingStrategy in class Configuration
Parameters:
namingStrategy - the NamingStrategy to set

getReflectionManager

public org.hibernate.annotations.common.reflection.ReflectionManager getReflectionManager()


Copyright © 2001-2010 Red Hat, Inc. All Rights Reserved.