Hibernate Tutorials

1. Fetching strategies in Hibernate

By: Dorris : 2011-01-01

Description: Hibernate uses a fetching strategy to retrieve associated objects if the application needs to navigate the association. Fetch strategies can be declared in the O/R mapping metadata, or over-ridden by a particular HQL or Criteria query.

2. equals() and hashCode() in Hibernate

By: Dorris : 2011-01-01

Description: Hibernate guarantees equivalence of persistent identity (database row) and Java identity only inside a particular session scope. When you mix instances retrieved in different sessions, you must implement equals() and hashCode() if you wish to have meaningful semantics for Sets.

3. Tuplizers (org.hibernate.tuple.Tuplizer) in Hibernate

By: Dorris : 2011-01-01

Description: org.hibernate.tuple.Tuplizer and its sub-interfaces are responsible for managing a particular representation of a piece of data given that representation's org.hibernate.EntityMode. If a given piece of data is thought of as a data structure, then a tuplizer is the thing that knows how to create such a data structure, how to extract values from such a data structure and how to inject values into such a data structure. For example, for the POJO entity mode, the corresponding tuplizer knows how create the POJO through its constructor. It also knows how to access the POJO properties using the defined property accessors.

4. EntityNameResolvers in Hibernate

By: Dorris : 2011-01-01

Description: org.hibernate.EntityNameResolver is a contract for resolving the entity name of a given entity instance. The interface defines a single method resolveEntityName which is passed the entity instance and is expected to return the appropriate entity name (null is allowed and would indicate that the resolver does not know how to resolve the entity name of the given entity instance). Generally speaking, an org.hibernate.EntityNameResolver is going to be most useful in the case of dynamic models. One example might be using proxied interfaces as your domain model. The hibernate test suite has an example of this exact style of usage under the org.hibernate.test.dynamicentity.tuplizer2. Here is some of the code from that package for illustration.

5. Hi/lo algorithm in Hibernate

By: Dorris : 2011-01-01

Description: The hilo and seqhilo generators provide two alternate implementations of the hi/lo algorithm. The first implementation requires a "special" database table to hold the next available "hi" value. Where supported, the second uses an Oracle-style sequence.

6. Identity columns and sequences in Hibernate

By: Dorris : 2011-01-01

Description: For databases that support identity columns (DB2, MySQL, Sybase, MS SQL), you can use identity key generation. For databases that support sequences (DB2, Oracle, PostgreSQL, Interbase, McKoi, SAP DB) you can use sequence style key generation. Both of these strategies require two SQL queries to insert a new object.

7. Assigned identifiers in Hibernate

By: Dorris : 2011-01-01

Description: If you want the application to assign identifiers, as opposed to having Hibernate generate them, you can use the assigned generator. This special generator uses the identifier value already assigned to the object's identifier property. The generator is used when the primary key is a natural key instead of a surrogate key. This is the default behavior if you do not specify @GeneratedValue nor <generator> elements.

8. Primary keys assigned by triggers in Hibernate

By: Dorris : 2011-01-01

Description: In the above example, there is a unique valued property named socialSecurityNumber. It is defined by the class, as a natural key and a surrogate key named person_id, whose value is generated by a trigger.

9. Formula in Hibernate

By: Dorris : 2011-01-01

Description: Sometimes, you want the Database to do some computation for you rather than in the JVM, you might also create some kind of virtual column. You can use a SQL fragment (aka formula) instead of mapping a property into a column. This kind of property is read only (its value is calculated by your formula fragment).

10. Step by Step Hibernate - Your First Hibernate Application

By: Felix : 2010-12-29

Description: This could well be your first Hibernate Application. In this tutorial a step by step approach is taken to show you how to use hibernate in your java applications. For this example, we will set up a small database application that can store events we want to attend and information about the host(s) of these events. This explains the basics of Hibernate. You can get started with Hibernate using this tutorial and extend the functionalities from here.