How to optimize unidirectional collections with JPA and Hibernate


Hibernate supports three data mapping types: basic (e.g String, int), Embeddable and Entity. Most often, a database row is mapped to an Entity, each database column being associated to a basic attribute. Embeddable types are more common when combining several field mappings into a reusable group (the Embeddable being merged into the owning Entity mapping structure).

Both basic types and Embeddables can be associated to an Entity through the @ElementCollection, in a one-Entity-many-non-Entity relationship.

Although we are going to explain these optimizations using an @ElementCollection, the same rules apply to any unidirectional @OneToMany or to both unidirectional and bidirectional @ManyToMany associations.

Continue reading “How to optimize unidirectional collections with JPA and Hibernate”

A beginner’s guide to Hibernate Types

The basic mapping concepts

When learning Hibernate, many like to jump to ParentChild associations without mastering the object relation mapping basics. It’s very important to understand the basic mapping rules for individual Entities before starting modelling Entity associations.

Hibernate types

A Hibernate type is a bridge between an SQL type and a Java primitive/Object type.

Continue reading “A beginner’s guide to Hibernate Types”