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.
The steps involved to create a HIT-based application are as follows:
Choose your database vendor, database driver, database name, user etc. and create a blank database
Obtain the HIT library and its dependencies via Ivy, Maven or Gradle (TBA, the artifacts will be available shortly)
Create a Hibernate entity
Create a subclass of AbstractDao for the entity
Create a subclass of AbstractSpringInitializer and any Spring configuration classes necessary
Edit the configuration files and run the application.
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
hit.properties - defines hit-specific properties and can be appended to to add application specific properties.
hibernate.properties - defines Hibernate-specific properties
ehcache.xml - configuration for EhCache second level caching
logback.xml - configuration for logging
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.
For simple, low to medium volume data access typically 6 properties are of importance when configuring a datasource:
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.