org.springframework.orm.jpa

## Class JpaAccessor

- java.lang.Object
- - org.springframework.orm.jpa.EntityManagerFactoryAccessor
  - - org.springframework.orm.jpa.JpaAccessor

All Implemented Interfaces:
  Aware, BeanFactoryAware, InitializingBean

Direct Known Subclasses:
  JpaInterceptor, JpaTemplate

Deprecated.
as of Spring 3.1, in favor of native EntityManager usage (typically obtained through `@PersistenceContext`)

    @Deprecated
    public abstract class JpaAccessor
    extends EntityManagerFactoryAccessor
    implements InitializingBean

Base class for JpaTemplate and JpaInterceptor, defining common properties such as EntityManagerFactory and flushing behavior.

Not intended to be used directly. See `JpaTemplate` and `JpaInterceptor`.

Since:
  2.0
Author:
  Juergen Hoeller
See Also:
  `EntityManagerFactoryAccessor.setEntityManagerFactory(javax.persistence.EntityManagerFactory)`, `setEntityManager(javax.persistence.EntityManager)`, `setJpaDialect(org.springframework.orm.jpa.JpaDialect)`, `setFlushEager(boolean)`, `JpaTemplate`, `JpaInterceptor`, `JpaDialect`

### Field Summary

### Fields inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor

`logger`

### Constructor Summary

Constructors
Constructor and Description
`JpaAccessor()` Deprecated.

### Method Summary

Methods
`void` `afterPropertiesSet()` Deprecated. Eagerly initialize the JPA dialect, creating a default one for the specified EntityManagerFactory if none set.
`protected void` `flushIfNecessary(EntityManager em, boolean existingTransaction)` Deprecated. Flush the given JPA entity manager if necessary.
`EntityManager` `getEntityManager()` Deprecated. Return the JPA EntityManager to use.
`JpaDialect` `getJpaDialect()` Deprecated. Return the JPA dialect to use for this accessor.
`boolean` `isFlushEager()` Deprecated. Return if this accessor should flush changes to the database eagerly.
`void` `setEntityManager(EntityManager entityManager)` Deprecated. Set the JPA EntityManager to use.
`void` `setFlushEager(boolean flushEager)` Deprecated. Set if this accessor should flush changes to the database eagerly.
`void` `setJpaDialect(JpaDialect jpaDialect)` Deprecated. Set the JPA dialect to use for this accessor.
`RuntimeException` `translateIfNecessary(RuntimeException ex)` Deprecated. Convert the given runtime exception to an appropriate exception from the `org.springframework.dao` hierarchy if necessary, or return the exception itself if it is not persistence related

### Methods inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor

`createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitName`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### JpaAccessor

    public JpaAccessor()

Deprecated.

### Method Detail

#### setEntityManager

    public void setEntityManager(EntityManager entityManager)

Deprecated.
Set the JPA EntityManager to use.

#### getEntityManager

    public EntityManager getEntityManager()

Deprecated.
Return the JPA EntityManager to use.

#### setJpaDialect

    public void setJpaDialect(JpaDialect jpaDialect)

Deprecated.
Set the JPA dialect to use for this accessor.

The dialect object can be used to retrieve the underlying JDBC connection, for example.

#### getJpaDialect

    public JpaDialect getJpaDialect()

Deprecated.
Return the JPA dialect to use for this accessor.

Creates a default one for the specified EntityManagerFactory if none set.

#### setFlushEager

    public void setFlushEager(boolean flushEager)

Deprecated.
Set if this accessor should flush changes to the database eagerly.

Eager flushing leads to immediate synchronization with the database, even if in a transaction. This causes inconsistencies to show up and throw a respective exception immediately, and JDBC access code that participates in the same transaction will see the changes as the database is already aware of them then. But the drawbacks are:

- additional communication roundtrips with the database, instead of a single batch at transaction commit;
- the fact that an actual database rollback is needed if the JPA transaction rolls back (due to already submitted SQL statements).

#### isFlushEager

    public boolean isFlushEager()

Deprecated.
Return if this accessor should flush changes to the database eagerly.

#### afterPropertiesSet

    public void afterPropertiesSet()

Deprecated.
Eagerly initialize the JPA dialect, creating a default one for the specified EntityManagerFactory if none set.

Specified by:
  `afterPropertiesSet` in interface `InitializingBean`

#### flushIfNecessary

    protected void flushIfNecessary(EntityManager em,
                        boolean existingTransaction)
                             throws PersistenceException

Deprecated.
Flush the given JPA entity manager if necessary.

Parameters:
  `em` - the current JPA PersistenceManage
  `existingTransaction` - if executing within an existing transaction
Throws:
  `PersistenceException` - in case of JPA flushing errors

#### translateIfNecessary

    public RuntimeException translateIfNecessary(RuntimeException ex)

Deprecated.
Convert the given runtime exception to an appropriate exception from the `org.springframework.dao` hierarchy if necessary, or return the exception itself if it is not persistence related

Default implementation delegates to the JpaDialect. May be overridden in subclasses.

Parameters:
  `ex` - runtime exception that occured, which may or may not be JPA-related
Returns:
  the corresponding DataAccessException instance if wrapping should occur, otherwise the raw exception
See Also:
  `DataAccessUtils.translateIfNecessary(java.lang.RuntimeException, org.springframework.dao.support.PersistenceExceptionTranslator)`