concept Hibernate in category spring

appears as: Hibernate, Hibernate
Spring in Practice

This is an excerpt from Manning's book Spring in Practice.

Hibernate was a pioneer in Java-based ORM. Eventually the idea caught on, and Sun created the Java Persistence API (JPA) standard around ORM, based in large part on Hibernate. Although you can use Hibernate in a standalone fashion, it’s a compliant JPA implementation. So you also have the option of using JPA and treating Hibernate as a persistence provider. This allows you to use JPA-based frameworks like Spring Data JPA, which you’ll pursue in the following recipe.

But you may prefer to use standardized JPA interfaces such as EntityManagerFactory and EntityManager when you implement your DAOs. This approach offers additional flexibility with respect to choosing a persistence provider. You can, of course, continue to use Hibernate, because it’s a mature JPA implementation. But you have other options, such as EclipseLink and OpenJPA. Figure 2.10 shows the JPA-based configuration.

Figure 2.10. DAOs call JPA interfaces. You can bind an arbitrary persistence provider to the interface (EclipseLink JPA, OpenJPA, Hibernate, and so on).

In addition to code examples, this recipe offers a high-level overview of ORM with Hibernate. A full discussion would take a whole book—indeed, the book exists: Java Persistence with Hibernate by Christian Bauer and Gavin King (Manning, 2006)—so we won’t attempt it here. But this overview should equip newbies to understand what’s happening in the code examples in the rest of the book.

Spring Dynamic Modules in Action

This is an excerpt from Manning's book Spring Dynamic Modules in Action.

The lightweight container and the aspect-oriented programming (AOP) system are the main building blocks of Spring. Besides these, Spring provides a common abstraction layer for transaction management, integration with various persistence solutions (plain JDBC, Hibernate, (JPA) as well as with Java enterprise technologies (JMS and JMX). The Spring Framework isn’t an all-or-nothing solution; you can choose the modules according to your needs, the lightweight container being the glue for the application and the Spring classes.

Figure 5.6. Classloading problem when Hibernate tries to load mapped classes for a component

When splitting an application into modules, some modules depend on each other and on third-party libraries. We therefore need a strict way to identify the modules. There are also subtleties that can make the notion of a dependency tricky: if a module uses Hibernate, it needs the Hibernate binaries to compile and at runtime. This can be different for a module that uses Spring: it can only use the lightweight container, so it doesn’t need the Spring binaries to compile but obviously does need them at runtime. We usually refer to this notion as the scope of the dependency.