Hibernate

  The approach to managing persistent data has been a key design decision in every software project we’ve worked on. Given that persistent data isn’t a new or unusual requirement for Java applications, you’d expect to be able to make a simple choice among similar, well-established persistence solutions. Think of web application frameworks (Struts versus […]

Starting a project (Hibernate)

  You want to start using Hibernate and Java Persistence, and you want to learn it with a step-by-step example. You want to see both persistence APIs and how you can benefit from native Hibernate or standardized JPA. This is what you’ll find in this topic: a tour through a straightforward “Hello World” application. However, […]

Domain models and metadata (Hibernate)

  The “Hello World” example in the previous topic introduced you to Hibernate; however, it isn’t useful for understanding the requirements of real-world applications with complex data models. For the rest of the topic, we use a much more sophisticated example application—CaveatEmptor, an online auction system—to demonstrate Hibernate and Java Persistence. We start our discussion […]

Mapping persistent classes (Hibernate)

  This topic presents the fundamental mapping options, explaining how classes and properties are mapped to tables and columns. We show and discuss how you can handle database identity and primary keys, and how various other metadata settings can be used to customize how Hibernate loads and stores objects. All mapping examples are done in […]

Inheritance and custom types (Hibernate)

  We deliberately didn’t talk much about inheritance mapping so far. Mapping a hierarchy of classes to tables can be a complex issue, and we’ll present various strategies in this topic. You’ll learn which strategy to choose in a particular scenario. The Hibernate type system, with all its built-in converters and transformers for Java value-typed […]

Mapping collections and entity associations (Hibernate)

  Two important (and sometimes difficult to understand) topics didn’t appear in the previous topics: the mapping of collections, and the mapping of associations between entity classes. Most developers new to Hibernate are dealing with collections and entity associations for the first time when they try to map a typical parent/child relationship. But instead of […]

Advanced entity association mappings (Hibernate)

  When we use the word associations, we always refer to relationships between entities. In the previous topic, we demonstrated a unidirectional many-to-one association, made it bidirectional, and finally turned it into a parent/children relationship (one-to-many and many-to-one with cascading options). One reason we discuss more advanced entity mappings in a separate topic is that […]

Legacy databases and custom SQL (Hibernate)

  Many examples presented in this topic are about “difficult” mappings. The first time you’ll likely have problems creating a mapping is with a legacy database schema that can’t be modified. We discuss typical issues you encounter in such a scenario and how you can bend and twist your mapping metadata instead of changing your […]

Working with objects (Hibernate)

  You now have an understanding of how Hibernate and ORM solve the static aspects of the object/relational mismatch. With what you know so far, it’s possible to solve the structural mismatch problem, but an efficient solution to the problem requires something more. You must investigate strategies for runtime data access, because they’re crucial to […]

Transactions and concurrency (Hibernate)

  In this topic, we finally talk about transactions and how you create and control units of work in a application. We’ll show you how transactions work at the lowest level (the database) and how you work with transactions in an application that is based on native Hibernate, on Java Persistence, and with or without […]