Example usage for javax.persistence EntityNotFoundException getCause

List of usage examples for javax.persistence EntityNotFoundException getCause

Introduction

In this page you can find the example usage for javax.persistence EntityNotFoundException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:fr.xebia.demo.wicket.blog.service.GenericService.java

@SuppressWarnings("unchecked")
public T get(Serializable id) throws ServiceException {
    try {/*w  w  w . j a  v  a  2 s .  c  o m*/
        EntityManager entityManager = currentEntityManager();
        T object = entityManager.find(getObjectClass(), id);
        if (object == null) {
            throw new ServiceException("Object Not Found (id=" + id + ')');
        }
        return object;
    } catch (EntityNotFoundException e) {
        logger.error(e.getCause(), e);
        throw new ServiceException("Object Not Found (id=" + id + ')', e);
    } catch (PersistenceException e) {
        logger.error(e.getCause(), e);
        throw new ServiceException("Can't retreive object", e);
    } finally {
        closeEntityManager();
    }
}