Clouds
Home

Hibernate 2.0 Introduction

Hibernate Mapping Declaration

Hibernate Development Code

Hibernate Generator

Inheritence Mapping

Hibernate Mapping Declaration


    Hibernate Mapping

Hibernate 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" />
  • schema (optional): the name of a database schema.
  • catalog (optional): the name 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 PropertyAccessor.
  • default-lazy (optional - defaults to true): the default value for unspecified lazy attributes of class and collection mappings.
  • auto-import (optional - defaults to true): specifies whether we can use unqualified class names of classes in this mapping in the query language.
  • package (optional): specifies a package prefix to use for unqualified class names in the mapping document.

Hibernate Class

<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" />
  • name (optional): the fully qualified Java class name of the persistent 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 table.
  • discriminator-value (optional - defaults 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 (optional): overrides the schema name specified by the root element.
  • catalog (optional): overrides the catalog name specified by the root element.
  • proxy (optional): specifies an interface to use for lazy initializing 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 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 a transient object has been associated with a new session using update(), will Hibernate perform an extra SQL SELECT to determine if an UPDATE is actually required.
  • polymorphism (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.
  • batch-size (optional - defaults to 1): specifies a "batch size" for fetching instances of this class by identifier.
  • optimistic-lock (optional - defaults to version): determines the optimistic locking strategy.
  • lazy (optional): lazy fetching can be disabled by setting lazy="false".
  • entity-name (optional - defaults to the class name): Hibernate3 allows a class to be mapped multiple times, potentially to different tables. It also allows entity mappings that are represented by Maps or XML at the Java level. In these cases, you should provide an explicit arbitrary name for the entity.
  • check (optional): an SQL expression used to generate a multi-row check constraint for automatic schema generation.
  • rowid (optional): Hibernate can use ROWIDs on databases. On Oracle, for example, Hibernate can use the rowid extra column for fast updates once this option has been set to rowid. A ROWID is an implementation detail and represents the physical location of a stored tuple.
  • subselect (optional): maps an immutable and read-only entity to a database subselect. This is useful if you want to have a view instead of a base table. See below for more information.
  • abstract (optional): is used to mark abstract superclasses in <union-subclass> hierarchies.

Overview of Hibernate JDBC properties

hibernate.connection.driverclass

determines the driver for connection. Example given below.
  • com.mysql.jdbc.Driver [ MYSQL JDBC driver]
  • oracle.jdbc.driver.OracleDriver [ Oracle JDBC driver]

    hibernate.connection.url

    This property determines where the database server located and how to connect with it. Example given below
  • jdbc:odbc://[host]/databasename [MYSQL]
  • :oracle:thin:@192.168.4.25:1521:dwh01 [Oracle]

    hibernate.connection.username

    determines username for database connection

    hibernate.connection.password

    determines username for database connection

    hibernate.dialect

    makes hibernate generate the appropriate SQL for chosen database.

    Hibernate.properties file sample

    hibernate.connection.driver_class =<driver name>
    hibernate.connection.url=<url of database connection>
    hibernate.connection.username =<connection username>
    hibernate.connection.password = <connection password>>
    hibernate.dialect=<SQL Translator>


    <<<< PREVIOUS: Introduction To Hibernate          NEXT: Hibernate Development Code >>>>


    Home Clouds