Details of hibernate.cfg.xml

Details of hibernate.cfg.xml

hibernate.connection.driver_class: The JDBC driver class
H2 – org.h2.Driver
Oracle – oracle.jdbc.driver.OracleDriver
MySql – com.mysql.jdbc.Driver

hibernate.connection.url: The JDBC URL to the database instance.
H2 – jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
Oracle – jdbc:oracle:thin:@
MySql – jdbc:mysql://localhost/DBNAME

hibernate.dialect: This property makes Hibernate generate the appropriate SQL for the chosen database.
H2 – org.hibernate.dialect.H2Dialect
Oracle – org.hibernate.dialect.OracleDialect
MySql – org.hibernate.dialect.MySQLDialect

hibernate.cache.provider_class: Caching implementation to use
No Cache – org.hibernate.cache.internal.NoCacheProvider
EHCache – org.hibernate.cache.EhCacheProvider
OSCache – org.hibernate.cache.OSCacheProvider
SwarmCache – org.hibernate.cache.SwarmCacheProvider
JBoss TreeCache – org.hibernate.cache.TreeCacheProvider

hibernate.connection.username: The database user name

hibernate.connection.password: The database user password

hibernate.connection.pool_size: Limits the number of connections waiting in the Hibernate database connection pool.

hibernate.show_sql: Echo all executed SQL to stdout Automatically validates or exports schema DDL to the database
create: creates the schema, destroying previous data
create-drop: drop the schema at the end of the session
validate: validate the schema, makes no changes to the database
update: update the schema

mapping resource: Resource mapping files

Sample XML




Hibernate Basics

Hibernate may not be the best solution for data-centric applications that only use stored-procedures to implement the business logic in the database, it is most useful with object-oriented domain models and business logic in the Java-based middle-tier.

Hibernate can certainly help you to remove or encapsulate vendor-specific SQL code and will help with the common task of result set translation from a tabular representation to a graph of objects.

Basic example
Pre-req: Spring STS

  1. Create new maven project (File > new > Maven Project)
  2. Add dependancies
  3. Add Employee entity class
  4. Add hibernate mapping class for Employee (Employee.hbm.xml)
  5. Add hibernate configuration (hibernate.cfg.xml)
  6. Test Add and list employees

Source: Employee Manager

Ref: Hibernate User dev guide