Example usage for org.hibernate JDBCException getSQLException

List of usage examples for org.hibernate JDBCException getSQLException

Introduction

In this page you can find the example usage for org.hibernate JDBCException getSQLException.

Prototype

public SQLException getSQLException() 

Source Link

Document

Get the underlying SQLException .

Usage

From source file:com.simple.cms.dao.UserDaoImpl.java

@Override
public User findUserByID(int userID) {

    User user;//from  ww  w.j  a v  a  2 s .c o m
    if (!dbSession.isOpen()) {
        dbSession = HibernateUtil.getSessionFactory().openSession();
    }
    try {
        dbSession.beginTransaction();

        user = (User) dbSession.get(User.class, userID);
        dbSession.getTransaction().commit();

        return user;
    } catch (JDBCException ex) {
        dbSession.getTransaction().rollback();
        dbSession.close();

        throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException());
    }

}

From source file:com.simple.cms.dao.UserDaoImpl.java

@Override
public List<User> findUsersByName(String name) {
    List<User> users;//www .  j  ava2  s . c  om
    if (!dbSession.isOpen()) {
        dbSession = HibernateUtil.getSessionFactory().openSession();
    }
    try {
        dbSession.beginTransaction();

        users = dbSession.createCriteria(User.class).add(Restrictions.ilike("name", name, MatchMode.ANYWHERE))
                .list();
        dbSession.getTransaction().commit();

        return users;
    } catch (JDBCException ex) {
        dbSession.getTransaction().rollback();
        dbSession.close();

        throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException());
    }

}

From source file:com.simple.cms.dao.UserDaoImpl.java

@Override
public List<User> findAllUser() {
    if (!dbSession.isOpen()) {
        dbSession = HibernateUtil.getSessionFactory().openSession();
    }//from  ww w  .  jav  a  2s.  c om
    try {
        dbSession.beginTransaction();
        List<User> users = dbSession.createCriteria(User.class).list();
        return users;
    } catch (JDBCException ex) {
        dbSession.getTransaction().rollback();
        dbSession.close();

        throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException());
    }
}

From source file:com.simple.cms.dao.UserDaoImpl.java

@Override
public User findUserByUserName(String userName) {
    User user;/*from w  w  w  . ja  v  a2 s.c o m*/
    if (!dbSession.isOpen()) {
        dbSession = HibernateUtil.getSessionFactory().openSession();
    }
    try {
        dbSession.beginTransaction();

        user = (User) dbSession.createCriteria(User.class).add(Restrictions.eq("userName", userName))
                .uniqueResult();

        dbSession.getTransaction().commit();

        return user;
    } catch (JDBCException ex) {
        dbSession.getTransaction().rollback();
        dbSession.close();

        throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException());
    }
}

From source file:org.beangle.commons.orm.hibernate.HibernateTransactionManager.java

License:Open Source License

/**
 * Convert the given Hibernate JDBCException to an appropriate exception
 * from the <code>org.springframework.dao</code> hierarchy, using the
 * given SQLExceptionTranslator.//from  w  w  w.j  a v a  2  s.  co  m
 * 
 * @param ex Hibernate JDBCException that occured
 * @param translator the SQLExceptionTranslator to use
 * @return a corresponding DataAccessException
 */
protected DataAccessException convertJdbcAccessException(JDBCException ex, SQLExceptionTranslator translator) {
    return translator.translate("Hibernate flushing: " + ex.getMessage(), ex.getSQL(), ex.getSQLException());
}

From source file:org.codehaus.grepo.query.hibernate.repository.DefaultHibernateRepository.java

License:Apache License

/**
 * Convert the given Hibernate JDBCException to an appropriate exception from the {@code org.springframework.dao}
 * hierarchy, using the given SQLExceptionTranslator.
 *
 * @param ex Hibernate JDBCException that occured
 * @param translator the SQLExceptionTranslator to use
 * @return a corresponding DataAccessException
 *///from   ww  w . j  a  va  2 s . c  om
protected DataAccessException convertJdbcAccessException(JDBCException ex, SQLExceptionTranslator translator) {
    return translator.translate("Hibernate operation: " + ex.getMessage(), ex.getSQL(), ex.getSQLException());
}

From source file:org.grails.orm.hibernate.GrailsHibernateTemplate.java

License:Apache License

protected DataAccessException convertJdbcAccessException(JDBCException ex, SQLExceptionTranslator translator) {
    String msg = ex.getMessage();
    String sql = ex.getSQL();//from w  ww .j  a v a  2  s.co m
    SQLException sqlException = ex.getSQLException();
    return translator.translate("Hibernate operation: " + msg, sql, sqlException);
}

From source file:org.kalypso.model.wspm.pdb.connect.Executor.java

License:Open Source License

private PdbConnectException logHibernateException(final HibernateException e) {
    if (e instanceof JDBCException) {
        final JDBCException je = (JDBCException) e;
        final SQLException sqlException = je.getSQLException();
        logSQLException(sqlException);/*  w  w  w. j  a va  2  s  .  c  om*/
    }

    e.printStackTrace();

    final String message = String.format(Messages.getString("Executor_0"), m_operation.getLabel()); //$NON-NLS-1$
    return new PdbConnectException(message, e);
}

From source file:org.springframework.orm.hibernate3.HibernateExceptionTranslator.java

License:Apache License

/**
 * Convert the given HibernateException to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * <p>Will automatically apply a specified SQLExceptionTranslator to a
 * Hibernate JDBCException, else rely on Hibernate's default translation.
 * @param ex HibernateException that occured
 * @return a corresponding DataAccessException
 * @see SessionFactoryUtils#convertHibernateAccessException
 * @see #setJdbcExceptionTranslator/*from  ww w .j av  a 2s .  com*/
 */
protected DataAccessException convertHibernateAccessException(HibernateException ex) {
    if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
        JDBCException jdbcEx = (JDBCException) ex;
        return this.jdbcExceptionTranslator.translate("Hibernate operation: " + jdbcEx.getMessage(),
                jdbcEx.getSQL(), jdbcEx.getSQLException());
    }
    return SessionFactoryUtils.convertHibernateAccessException(ex);
}

From source file:org.springframework.orm.hibernate3.SpringSessionSynchronization.java

License:Apache License

private DataAccessException translateException(HibernateException ex) {
    if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
        JDBCException jdbcEx = (JDBCException) ex;
        return this.jdbcExceptionTranslator.translate("Hibernate flushing: " + jdbcEx.getMessage(),
                jdbcEx.getSQL(), jdbcEx.getSQLException());
    }//from  w w w. j  a  va  2s . co  m
    return SessionFactoryUtils.convertHibernateAccessException(ex);
}