Category Archives: JPA/Hibernate

JPA OneToMany Relationship

1. Introduction. The OneToMany relationship is the most common JPA association and foreign key is controlled by the child-side directly including unidirectional and bidirectional association. This note presents how to configure bidirectional @OneToMany association 2. Bidirectional ManyToOne / OneToMany Relationships. Assuming that: Event entity references a single instance of User entity User entity references a… Read More »

JPA OneToOne Relationship

In JPA, two types of the @OneToOne relationships are bidirectional and unidirectional. In each type, we can use different mapping approaches: One-to-one association that maps a foreign key column. One-to-one association where both source and target share the same primary key values. One-to-one association from an embeddable class to another entity. 1. Bidirectional OneToOne association… Read More »

Hibernate cache in theory

The note will follow: 1. Introduction. Hibernate has a two-level cache architecture: first-level cache and second-level cache. Figure 1: Hibernate’s two levels cache (source: Manning) The first-level cache is the persistence context cache (scope of Session). The cache ensures that when the application requests the same persistent object twice in a particular session, it gets back… Read More »