Hibernate Configuration
Configuration Object
- It represents a configuration or properties file required by the Hibernate and usually created only once during application initialization.
- It provides two keys components:
Database Connection:This is handled through configuration file supported by Hibernate hibernate.cfg.xml.Class Mapping Setup:This component creates the connection between the Java classes and database tables.Configuring hibernate.cfg.xml
- Configuration settings related to DB & other related parameters :Connection Driver, URL, username, password.
- Defines Mapping information between the Java classes & the database tables.
- Object/relational mappings are usually defined in an XML document.
- The mapping document is designed to be readable and hand-editable.
- The mapping language is Java-centric, meaning that mappings are constructed around persistent class declarations and not table declarations.
Hibernate-Mapping
schema: (optional) the name of a database schema.catalog: (optional)then ame of a database catalog.default-cascade:(optional- defaults to none) a default cascade style.default-access: (optional-defaults to property)the strategy Hibernate should use for accessing all properties. It can be a custom implementation of Property Accessor.default-lazy: (optional-default to true) the default value for unspecified lazy attributes of class and collection mappings .default-import:(optional-default to true) specifies whether we can unqualified class names of classes in this mapping in the query language.class
Name:(optional)the fully qualify java class name of the persistence class or interface. If this attribute is missing, it is assumed that the mapping is for a non-POJO entity.table:(optional - defaults to the unqualified class name) the name of its database tablediscriminator-value:(optional-default to the class name)a value that distinguishes individual subclasses that is used for polymorphic behavior. Acceptable values include null and not null.mutable:(optional-defaults to true)Specifies that instances of the class are (not) mutable.schema:(opitonal)overrides the schema name specified by the root<hibernate-mapping> elementcatalog:(opitonal) overrides the catalog name specified by the root < hibernate-mapping> elementproxy:(opitonal)Specifies an interface to use the lazy intializing proxies. You can specify the name of the class itself.dynamic-update:(optional-defaults to false)Specifies that UPDATE SQL should be generated at runtime and can contain only those columns whose values have changed.dynamic-insert:(optional-defaults to false)Specifies that INSERT SQL should be generated at runtime and can contain only the columns whose values are not null.select-before-update:(optional- defaults to false) Specifies that Hibernate should never perform an SQL UPDATE unless it is certain that an object is actually modified. Only when transient object has been associated with a new session using update(), will Hibernate perform an extra SQL SELECT to determine if an UPDDATE is actually required.polymnorphism :(optional - defaults to implicit)determines whether implicit or explicit query polymorphism is used.where :(optional)Specifies an arbitrary SQL WHERE condition to be used when retrieving objects of this class.persister:(opiotnal)specifies a custom ClassPersister.batch-size:(optional- defaults to 1) Specifies a "batch-size" for fetching instances of this class by identifier.optimistic-look :(optional - defaults to version) determines the optimistic locking strategy.Id, Composite Id and Generators
name:(optional)the name of the identifier property.type:(optional)a name that indicates the Hibernate type.column:(optional-defaults to the property name)the name of the primary key column.unsaved-value:(optional- defaults to a "sensible" value)an identifier property value that indicates an instance is newly instantiated(unsaved). distinguishing it from detached instances that were saved or loaded in a previous session.access:(optional- defaults to property)the strategy Hibernate should use for accessing the property value.Property
name:(optional)the name of the property, with an initial lowercase letter.colums:(optional-defaults to the property name) the name of the mapped database table column. this can also be specified by nested < column> element(s).type:(optional)a name that indicates the Hibernate type.update,insert:(optional-defaults to true)Specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements.formula:(optional)an SQL expression that defines the value for a computed property. Computed properties do not have a column mapping of their own.access:(optional-defaults to property)the strategy Hibernate uses for accessing the property value.lazy:(optional-defaults to false)Specifies that this property should be fetched lazily when the instance variable is first accessed.unique:(optional)enables the DDL generation of a unique constraints for the columns.not-null:(optional)enables the DDL generation of a nullability constraints for the columns.optimistic-lock:(optional -defaults to true) Specifies that updates to this property do or do not require acquisition of the optimistic lock.generated:(optional- defaults to never) Specifies that this property value is actually generated by the database.One to one
name:(optional)the name of the property.class:(optional - defaults to the property type determined by reflection) the name of the associated class.cascade:(optional)Specifies which operations should be cascaded from the bject to the associated object.constrained:(optional) Specifies that a foreign key constraint on the primary key of the mapped table and reference the table of the associated class.fetch:(optional-defaults to select)Chooses between outer-join fetching or sequential select fetching.property-ref:(optional)the name of a property of the associated class that is joined to this foreign key. If not specified, the primary key of the associated class is used.access:(optional-defaults to property)the strategy Hibernate uses for accessing the property value.formula:(optional)an SQL expression that defines the value for a computed property. Computed properties do not have a column mapping of their own.update,insert:(opiotnal-defaults to true) Specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements.lazy:(optional-defaults to false)Specifies that this property should be fetched lazily when the instance variable is first accessed.entity-name:(optional) the entity name of the associated class.Many to one
name:(optional) the name of the property.columns:(optional)the name of the foreign key . This can also be specified by nested < column> element(s).class:(optional - defaults to the property type determined by reflection)the name of the associated class.cascade:(optional)Specifies which operations should be cascaded from the object to the associated object.fetch:(optional-defaults to select) Chooses between outer-join fetching or sequential select fetching.update,insert:(optional-defaults to true)Specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements.property-ref:(optional)the name of a property of the associated class that is joined to this foreign key. If not specified, the primary key of the associated class is used.access:(optional-defaults to property)the strategy Hibernate uses for accessing the property value.unique:(optional)enables the DDL generation of a unique constraints for the columns.not-null:(optional)enables the DDL generation of a nullability constraints for the columns.optimistic-lock:(optional -defaults to true) Specifies that updates to this property do or do not require acquisition of the optimistic lock.lazy:(optional-defaults to false)Specifies that this property should be fetched lazily when the instance variable is first accessed.not-found:(optional- defaults to exception)Specifies how foreign keys that reference missing rows will be handled, ignore will treat a missing row as a null association.entity-name:(optional)the entity name of the associated class.formula:(optional)an SQL expression that defines the value for a computed property. Computed properties do not have a column mapping of their own.
Basic O/R Mapping
< hibernate-mapping schema="schemaName" catalog="catalogName" default-cascade="cascade_style" default-access="field|property|className" default-lazy="true|false" auto-import="true|false" package="package.name" />
<class name="ClassName" table="tableName" discriminator-value="discriminator_value" mutable="true|false" schema="owner" catalog="catalog" proxy="proxyInterface" dynamic-update="true|false" dynamic-insert="true|false" select-before-update="true|false" polymorphism="implicit|explicit" where="arbitrary sql where condition" persister="PersisterClass" batch-size="N" optimistic-lock="none|version|dirty|all" lazy="true|false" entity-name="EntityName" check="arbitrary sql check condition" rowid="rowid" subselect="SQL expression" abstract="true|false" node="element-name" />
< id name="propertyName" type="typename" column="column_name" unsaved-value="null|any|none|undefined|id_value" access="field|property|ClassName"> </id>
<property name="propertyName" column="column_name" type="type name" update="true|false" insert="true|false" formula="arbitrary SQL expression" access="field|property|ClassName" lazy="true|false" unique="true|false" not-null="true|false" optimistic-lock="true|false" generated="never|insert|always" />
<many-to-one name="propertyName" class="className" cascade="cascade_style" constrained="true|false" fetch="join|select" property-ref="propertyNameFromAssociatedClass" access="field|property|ClassName" formula="arbitrary SQL expression" lazy="true|false" entity-name="EntityName" node="element-name|@attribute-name|element/@attribute|." embed-xml="true|false" foreign-key="foreign_key_name" />
<many-to-one name="propertyName" column="column_name" class="className" cascade="cascade_style" fetch="join|select" update="true|false" insert="true|false" property-ref="propertyNameFromAssociatedClass" access="field|property|ClassName" unique="true|false" not-null="true|false" optimistic-lock="true|false" lazy="true|false" not-found="true|false" entity-name="EntityName" formula="arbitrary SQL expression" />


