HIT

HIT: A Hibernate quickstart

View the Project on GitHub mrstampy/hitman

HIT: A Hibernate quickstart

HIT - Hibernate Induction Trigger - is a library intended to provide all the configuration and dependencies necessary to begin implementing a stand-alone database-backed Spring/Hibernate application, enabling logging, JMX control, transactional boundaries and second level caching. The example code demonstrates the use of the library; a prototype Spring/Hibernate application can be developed in minutes. A Java 6 runtime (minimum) is required.

HIT on G+

Version 1.2 - released 14/03/14

Version 1.1 - released 5/03/14

Usage

The steps involved to create a HIT-based application are as follows:

  1. Choose your database vendor, database driver, database name, user etc. and create a blank database

  2. Obtain the HIT library and its dependencies via Ivy, Maven or Gradle (TBA, the artifacts will be available shortly)

    • Ivy - sample Ivy file
    • Maven:
      <dependency>
        <groupId>com.github.mrstampy</groupId>
        <artifactId>hit</artifactId>
        <version>1.2</version>
      </dependency>
  3. Create a Hibernate entity

  4. Create a subclass of AbstractDao for the entity

  5. Create a subclass of AbstractSpringInitializer and any Spring configuration classes necessary

  6. Edit the configuration files and run the application.

Configuration

Four configuration files are necessary to use HIT and must be available on the classpath:

https://github.com/mrstampy/hitman/tree/master/hitman/config https://github.com/mrstampy/hitman/tree/master/hitman/example.config

  1. hit.properties - defines hit-specific properties and can be appended to to add application specific properties.

  2. hibernate.properties - defines Hibernate-specific properties

  3. ehcache.xml - configuration for EhCache second level caching

  4. logback.xml - configuration for logging

DataSource

Included in the distribution are four implementations of a DataSource JDBC connection pool:

To switch between the four change the value of the property 'data.source.creator.type' in hit.properties. Once a connection pool has been chosen for your application the other CP jar dependencies can be excluded from the application build.

*Tomcat JDBC uses the JULI logging framework. There is no official juli-over-slf4j jar file, however adding the classes from https://github.com/pellcorp/juli-over-slf4j to your application will enable logging for this connection pool.

DataSource Configuration

For simple, low to medium volume data access typically 6 properties are of importance when configuring a datasource:

  1. The JDBC driver class
  2. The JDBC URL to the database
  3. The username for the database
  4. The password for the database
  5. The maximum number of connections the datasource can pool
  6. The minimum number of connections in the pool when idle

As each datasource implementation varies in its configuration API, the value of these properties are set via the values in 'hibernate.properties' (the first four) and 'hit.properties' (the last two). Should greater configuration control be required a datasource-specific properties file can be made available on the classpath and specified by the 'datasource.property.file' property in 'hit.properties', with the exception of the first four properties which are always set from 'hibernate.properties' values.