Hibernate Tutorials

1. Step by Step Hibernate - Your First Hibernate Application

By: Felix : 2023-05-08

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.

2. A sample Hibernate Web Application using Servlets

By: Felix : 2023-05-08

Description: A Hibernate web application uses Session and Transaction almost like a standalone application. However, some common patterns are useful. You can now write an EventManagerServlet. This servlet can list all events stored in the database, and it provides an HTML form to enter new events.

3. Programmatic configuration in Hibernate

By: Felix : 2022-12-29

Description: An instance of org.hibernate.cfg.Configuration represents an entire set of mappings of an application's Java types to an SQL database. The org.hibernate.cfg.Configuration is used to build an immutable org.hibernate.SessionFactory. The mappings are compiled from various XML mapping files.

4. Tutorial Using the Java Persistence API (JPA) in Hibernate

By: Felix : 2022-12-28

Description: Instead of using the Hibernate-specific hibernate.cfg.xml configuration file, JPA, defines a different bootstrap process that uses its own configuration file named persistence.xml. How this bootstrapping works is defined by the JPA specification. In Javaâ„¢ SE environments the persistence provider (Hibernate in this case) is required to locate all JPA configuration files by classpath lookup of the META-INF/persistence.xml resource name.

5. 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).

6. 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.

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. 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.

9. 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.

10. 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.