Example usage for org.springframework.orm.jpa JpaDialect translateExceptionIfPossible

List of usage examples for org.springframework.orm.jpa JpaDialect translateExceptionIfPossible

Introduction

In this page you can find the example usage for org.springframework.orm.jpa JpaDialect translateExceptionIfPossible.

Prototype

@Nullable
DataAccessException translateExceptionIfPossible(RuntimeException ex);

Source Link

Document

Translate the given runtime exception thrown by a persistence framework to a corresponding exception from Spring's generic org.springframework.dao.DataAccessException hierarchy, if possible.

Usage

From source file:org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.java

/**
 * Implementation of the PersistenceExceptionTranslator interface, as
 * autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
 * <p>Uses the dialect's conversion if possible; otherwise falls back to
 * standard JPA exception conversion./*  w w w . j  a v a2  s.  co m*/
 * @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
 * @see JpaDialect#translateExceptionIfPossible
 * @see EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible
 */
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
    JpaDialect jpaDialect = getJpaDialect();
    return (jpaDialect != null ? jpaDialect.translateExceptionIfPossible(ex)
            : EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex));
}