Top Description Interfaces Classes Enums
[default module]

Package org.hibernate.cfg


This package defines APIs for configuring Hibernate.

Note that all the real meat behind these APIs is defined in the package org.hibernate.boot.

Configuration properties may be specified:

We now present a couple of example configuration files.

Example JPA configuration file

The following JPA configuration may be specified in a file named persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

    <persistence-unit name="postgresql-example" transaction-type="RESOURCE_LOCAL">

        <class>org.hibernate.orm.example.Author</class>
        <class>org.hibernate.orm.example.Book</class>

        <properties>

            <!-- PostgreSQL -->
            <property name="javax.persistence.jdbc.url"
                      value="jdbc:postgresql://localhost/library"/>

            <!-- Credentials -->
            <property name="javax.persistence.jdbc.user"
                      value="hibernate"/>
            <property name="javax.persistence.jdbc.password"
                      value="hibernate"/>

            <!-- Agroal connection pool config -->
            <property name="hibernate.agroal.maxSize"
                      value="10"/>
            <property name="hibernate.agroal.acquisitionTimeout"
                      value="PT1s"/>
            <property name="hibernate.agroal.reapTimeout"
                      value="PT10s"/>

            <!-- Automatic schema export -->
            <property name="javax.persistence.schema-generation.database.action"
                      value="drop-and-create"/>

            <!-- SQL statement logging -->
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.highlight_sql" value="true"/>

        </properties>
    </persistence-unit>

</persistence>
The JPA configuration file is necessary when bootstrapping Hibernate via jakarta.persistence.Persistence#createEntityManagerFactory(java.lang.String).

Example native configuration file

The following configuration may be specified in a file named hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- PostgreSQL -->
        <property name="javax.persistence.jdbc.url">jdbc:postgresql://localhost/library</property>

        <!-- Credentials -->
        <property name="hibernate.connection.username">hibernate</property>
        <property name="hibernate.connection.password">hibernate</property>

        <!-- Agroal connection pool config -->
        <property name="hibernate.agroal.maxSize">10</property>
        <property name="hibernate.agroal.acquisitionTimeout">PT1s</property>
        <property name="hibernate.agroal.reapTimeout">PT10s</property>

        <!-- Automatic schema export -->
        <property name="hibernate.hbm2ddl.auto">create</property>

        <!-- SQL statement logging -->
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.format_sql">true</property>
        <property name="hibernate.highlight_sql">true</property>

        <!-- Maximum JDBC batch size -->
        <property name="hibernate.jdbc.batch_size">10</property>

        <!-- Entity classes -->
        <mapping class="org.hibernate.orm.example.Author"/>
        <mapping class="org.hibernate.orm.example.Book"/>

    </session-factory>
</hibernate-configuration>
The native configuration file is used when configuring Hibernate via org.hibernate.cfg.Configuration#configure() or org.hibernate.boot.registry.StandardServiceRegistryBuilder#configure().

Interface Summary

Modifier and TypeInterface and Description
public interface
AvailableSettings

Enumerates the configuration properties supported by Hibernate, including properties defined by the JPA specification.

public interface
public interface
BytecodeSettings

Settings which control the org.hibernate.bytecode.spi.BytecodeProvider used for bytecode enhancement and reflection optimization.

public interface
public interface
CacheSettings

Settings for Hibernate's second-level caching

public interface
DialectSpecificSettings

Settings used as fallback to configure aspects of specific org.hibernate.dialect.Dialects when the boot process does not have access to a java.sql.DatabaseMetaData object or its underlying JDBC java.sql.Connection.

public interface
public interface
public interface
JdbcSettings

Settings related to JDBC, Connections, pools, Dialects, etc

public interface
public interface
public interface
public interface
public interface
NamingStrategy

A set of rules for determining the physical column and table names given the information in the mapping document.
public interface
PersistenceSettings

Settings related to persistence-units

public interface
public interface
public interface
public interface
SecondPass

Deprecated for removal since 6. Use org.hibernate.boot.spi.SecondPass instead
Hibernate builds its build-time model incrementally, often delaying operations until other pieces of information are available.
public interface
public interface
public interface
public interface

Class Summary

Modifier and TypeClass and Description
public class
Configuration

A convenience API making it easier to bootstrap an instance of Hibernate.

public class
DefaultComponentSafeNamingStrategy

Deprecated NamingStrategy itself has been deprecated
public class
DefaultNamingStrategy

Deprecated NamingStrategy itself has been deprecated
The default NamingStrategy
public class
Environment

Provides access to configuration properties passed in Properties objects.

public class
ImprovedNamingStrategy

Deprecated NamingStrategy itself has been deprecated
An improved naming strategy that prefers embedded underscores to mixed case names
public class
PersistenceStandardNamingStrategy

Deprecated NamingStrategy itself has been deprecated
Naming strategy implementing the EJB3 standards
public class
RecoverableException

Deprecated Was only ever referenced in a single place, in an extremely dubious way.
An exception that indicates a condition where the hope is that subsequent processing will be able to recover from it.

Enum Summary

Modifier and TypeEnum and Description
public enum
MetadataSourceType

Deprecated for removal since 6. hbm.xml mappings are no longer supported, making this attribute irrelevant
Enumeration of the types of sources of mapping metadata