Example usage for org.springframework.orm.jpa EntityManagerFactoryUtils convertJpaAccessExceptionIfPossible

List of usage examples for org.springframework.orm.jpa EntityManagerFactoryUtils convertJpaAccessExceptionIfPossible

Introduction

In this page you can find the example usage for org.springframework.orm.jpa EntityManagerFactoryUtils convertJpaAccessExceptionIfPossible.

Prototype

@Nullable
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) 

Source Link

Document

Convert the given runtime exception to an appropriate exception from the org.springframework.dao hierarchy.

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.//from   w ww .java  2 s. c o  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));
}

From source file:org.springframework.orm.jpa.vendor.HibernateJpaDialect.java

@Override
@Nullable//  w ww  .  j ava 2s .c  o m
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
    if (ex instanceof HibernateException) {
        return convertHibernateAccessException((HibernateException) ex);
    }
    if (ex instanceof PersistenceException && ex.getCause() instanceof HibernateException) {
        return convertHibernateAccessException((HibernateException) ex.getCause());
    }
    return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
}