How to implement an AttributeConverter to support custom types
| |

How to implement an AttributeConverter to support custom types

All JPA implementations, including Hibernate, provide default mappings for a huge set of standard Java classes. You could model the attributes of all your entity classes using those mappings, and you would be able to map all columns of your table model. But this is often not the best fit for your business logic. A…

Native Queries – How to call native SQL queries with JPA & Hibernate
| | |

Native Queries – How to call native SQL queries with JPA & Hibernate

The Java Persistence Query Language (JPQL) is the most common way to query data from a database with JPA. It enables you to reuse your mapping definitions and is easier to use than SQL. But it supports only a small subset of the SQL standard, and it also provides no support for database-specific features. So…

Why, When and How to Use DTO Projections with JPA and Hibernate
|

Why, When and How to Use DTO Projections with JPA and Hibernate

DTOs are easy to use and the most efficient projection for read-only operations. So, whenever you don’t need to change the requested information, you should prefer a DTO projection. But what exactly is a DTO? How does such a projection work with Hibernate? And how can you use it in your queries? I will answer…

Hibernate Tip: Map a bidirectional one-to-one association with shared composite primary key
|

Hibernate Tip: Map a bidirectional one-to-one association with shared composite primary key

Hibernate Tips is a series of posts in which I describe a quick and easy solution for common Hibernate questions. If you have a question for a future Hibernate Tip, please post a comment below. Question: Today’s question was inspired by a question I answered on StackOverflow:How can I map a bidirectional one-to-one association that…

Implementing the Repository pattern with JPA and Hibernate
|

Implementing the Repository pattern with JPA and Hibernate

The repository pattern is extremely popular. In its modern interpretation, it abstracts the data store and enables your business logic to define read and write operations on a logical level. It does that by providing a set of methods to read, persist, update and remove an entity from the underlying data store. Old vs. modern…