Example usage for org.springframework.orm.hibernate5 SessionFactoryUtils convertHibernateAccessException

List of usage examples for org.springframework.orm.hibernate5 SessionFactoryUtils convertHibernateAccessException

Introduction

In this page you can find the example usage for org.springframework.orm.hibernate5 SessionFactoryUtils convertHibernateAccessException.

Prototype

public static DataAccessException convertHibernateAccessException(HibernateException ex) 

Source Link

Document

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

Usage

From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java

public void removeUser(User user) {
    try {// w w  w. j  a v  a  2s .c o m
        // TODO: should probably let db take care of this with
        // cacade constaint
        deleteAllPasswordRecoveries(user);

        getSession().delete(user);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java

public User updateUser(User user) {
    try {//  w  w w . ja v  a  2 s  . c  om
        // prevent auto flushing when querying for existing users
        getSession().setFlushMode(FlushMode.MANUAL);

        User findUser = findUserByUsernameOrEmailIgnoreCaseAndId(getBaseModelObject(user).getId(),
                user.getUsername(), user.getEmail());

        if (findUser != null) {
            if (findUser.getEmail().equals(user.getEmail())) {
                throw new DuplicateEmailException(user.getEmail());
            } else {
                throw new DuplicateUsernameException(user.getUsername());
            }
        }

        user.updateTimestamp();
        getSession().update(user);
        getSession().flush();

        return user;
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    } catch (ConstraintViolationException cve) {
        logConstraintViolationException(cve);
        throw cve;
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java

public void createPasswordRecovery(PasswordRecovery passwordRecovery) {
    try {//  w ww  . j  a  va 2 s. c o  m
        getSession().save(passwordRecovery);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java

public PasswordRecovery getPasswordRecovery(String key) {
    try {// w  w  w .  j  av a 2  s  .co m
        Query hibQuery = getSession().getNamedQuery("passwordRecovery.byKey").setParameter("key", key);
        hibQuery.setCacheable(true);
        return (PasswordRecovery) hibQuery.uniqueResult();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java

public void deletePasswordRecovery(PasswordRecovery passwordRecovery) {
    try {/*from   w ww  .  jav  a 2 s. c  o m*/
        getSession().delete(passwordRecovery);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}