public abstract class

JpaDaoSupport

extends DaoSupport
java.lang.Object
   ↳ org.springframework.dao.support.DaoSupport
     ↳ org.springframework.orm.jpa.support.JpaDaoSupport

Class Overview

Convenient super class for JPA data access objects. Intended for JpaTemplate usage. Alternatively, JPA-based DAOs can be coded against the plain JPA EntityManagerFactory/EntityManager API.

Requires an EntityManagerFactory or EntityManager to be set, providing a JpaTemplate based on it to subclasses. Can alternatively be initialized directly via a JpaTemplate, to reuse the latter's settings such as the EntityManagerFactory, JpaDialect, flush mode, etc.

This class will create its own JpaTemplate if an EntityManagerFactory or EntityManager reference is passed in. A custom JpaTemplate instance can be used through overriding createJpaTemplate.

Summary

[Expand]
Inherited Fields
From class org.springframework.dao.support.DaoSupport
Public Constructors
JpaDaoSupport()
Public Methods
final JpaTemplate getJpaTemplate()
Return the JpaTemplate for this DAO, pre-initialized with the EntityManagerFactory or set explicitly.
final void setEntityManager(EntityManager entityManager)
Set the JPA EntityManager to be used by this DAO.
final void setEntityManagerFactory(EntityManagerFactory entityManagerFactory)
Set the JPA EntityManagerFactory to be used by this DAO.
final void setJpaTemplate(JpaTemplate jpaTemplate)
Set the JpaTemplate for this DAO explicitly, as an alternative to specifying a EntityManagerFactory.
Protected Methods
final void checkDaoConfig()
Abstract subclasses must override this to check their configuration.
JpaTemplate createJpaTemplate(EntityManager entityManager)
Create a JpaTemplate for the given EntityManager.
JpaTemplate createJpaTemplate(EntityManagerFactory entityManagerFactory)
Create a JpaTemplate for the given EntityManagerFactory.
[Expand]
Inherited Methods
From class org.springframework.dao.support.DaoSupport
From class java.lang.Object
From interface org.springframework.beans.factory.InitializingBean

Public Constructors

public JpaDaoSupport ()

Public Methods

public final JpaTemplate getJpaTemplate ()

Return the JpaTemplate for this DAO, pre-initialized with the EntityManagerFactory or set explicitly.

public final void setEntityManager (EntityManager entityManager)

Set the JPA EntityManager to be used by this DAO. Will automatically create a JpaTemplate for the given EntityManager.

public final void setEntityManagerFactory (EntityManagerFactory entityManagerFactory)

Set the JPA EntityManagerFactory to be used by this DAO. Will automatically create a JpaTemplate for the given EntityManagerFactory.

public final void setJpaTemplate (JpaTemplate jpaTemplate)

Set the JpaTemplate for this DAO explicitly, as an alternative to specifying a EntityManagerFactory.

Protected Methods

protected final void checkDaoConfig ()

Abstract subclasses must override this to check their configuration.

Implementors should be marked as final

protected JpaTemplate createJpaTemplate (EntityManager entityManager)

Create a JpaTemplate for the given EntityManager. Only invoked if populating the DAO with a EntityManager reference!

Can be overridden in subclasses to provide a JpaTemplate instance with different configuration, or a custom JpaTemplate subclass.

Parameters
entityManager the JPA EntityManager to create a JpaTemplate for
Returns
  • the new JpaTemplate instance

protected JpaTemplate createJpaTemplate (EntityManagerFactory entityManagerFactory)

Create a JpaTemplate for the given EntityManagerFactory. Only invoked if populating the DAO with a EntityManagerFactory reference!

Can be overridden in subclasses to provide a JpaTemplate instance with different configuration, or a custom JpaTemplate subclass.

Parameters
entityManagerFactory the JPA EntityManagerFactory to create a JpaTemplate for
Returns
  • the new JpaTemplate instance