One to One Hibernate/JPA Example

In this tutorial we will demonstrate how to set up a One-to-One Mapping using annotations and MySQL as database. We will use a Worker table which is mapped one-to-one with an Info table which contains the info about the workers.

Read more: One to One Hibernate/JPA Example

One to Many Hibernate/JPA example

Here's an example which uses a One-to-Many mapping between the Table Customer (ONE) and Request (MANY).

Read more: One to Many Hibernate/JPA example

How to map MySQL auto increment field

MySQL does not have the concept of sequence but uses AUTO_INCREMENT fields to emulate sequence behaviour. Supposing that you have just created this table:

mysql> create table customer (id integer auto_increment, name varchar(25));
Query OK, 0 rows affected (0.03 sec)

Then you can map the id field using a Generation type IDENTITY:

public class Customer  {

    private Long id;

    private String name;

How to map an Oracle Sequence

This tutorial describes how to map an Oracle Sequence with JPA.

Read more: How to map an Oracle Sequence

Hibernate Data Filters

Filtering data is one of the most common Task of an application. This is usually achieved by adding WHERE clauses to your queries. In case the filters are defined dynamically by the user it becomes a more complex issue. A very powerful option for creating dynamic conditions to your applications are Criteria API, however it's likely that when conditions change, you will need to apply changes in your Criteria queries as well.

Read more: Hibernate Data Filters

Follow us on Twitter