Hibernate ORM JDBCException - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM JDBCException class.

This code example shows how to use the following methods:getMessage, getErrorCode, getSQLState
@SuppressWarnings("serial") 
public class HibernateJdbcException extends UncategorizedDataAccessException {
 
	public HibernateJdbcException(JDBCException ex) {
		super("JDBC exception on Hibernate data access: SQLException for SQL [" + ex.getSQL() + "]; SQL state [" +
				ex.getSQLState() + "]; error code [" + ex.getErrorCode() + "]; " + ex.getMessage(), ex);
	} 
 
	/** 
	 * Return the underlying SQLException. 
	 */ 
	public SQLException getSQLException() {
		return ((JDBCException) getCause()).getSQLException();
	} 
 
	/** 
	 * Return the SQL that led to the problem. 
	 */ 
	public String getSql() {
		return ((JDBCException) getCause()).getSQL();
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getErrorCode, getSQL, getSQLState, getMessage
 */ 
@SuppressWarnings("serial") 
public class HibernateJdbcException extends UncategorizedDataAccessException {
 
	public HibernateJdbcException(JDBCException ex) {
		super("JDBC exception on Hibernate data access: SQLException for SQL [" + ex.getSQL() + "]; SQL state [" +
				ex.getSQLState() + "]; error code [" + ex.getErrorCode() + "]; " + ex.getMessage(), ex);
	} 
 
	/** 
	 * Return the underlying SQLException. 
	 */ 
	public SQLException getSQLException() {
		return ((JDBCException) getCause()).getSQLException();
	} 
 
	/** 
	 * Return the SQL that led to the problem. 
	 */ 
	public String getSql() {
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMessage, getSQL, getSQLException
	 */ 
	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);
	} 
 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMessage, getErrorCode, getSQLState
import org.hibernate.QueryTimeoutException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.StaleObjectStateException;
import org.hibernate.StaleStateException;
import org.hibernate.TransientObjectException;
import org.hibernate.UnresolvableObjectException;
import org.hibernate.WrongClassException;
import org.hibernate.dialect.lock.OptimisticEntityLockException;
import org.hibernate.dialect.lock.PessimisticEntityLockException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.exception.DataException;
import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.exception.SQLGrammarException;
import org.hibernate.service.spi.Wrapped;
 
import org.springframework.dao.CannotAcquireLockException; 
import org.springframework.dao.DataAccessException; 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMessage, getSQL, getSQLException
 
	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());
		} 
		return SessionFactoryUtils.convertHibernateAccessException(ex);
	} 
 
	@Override 
	public void beforeCompletion() { 
		if (this.jtaTransaction != null) {
			// Typically in case of a suspended JTA transaction: 
			// Remove the Session for the current JTA transaction, but keep the holder. 
			Session session = this.sessionHolder.removeSession(this.jtaTransaction);
			if (session != null) {
				if (this.sessionHolder.isEmpty()) {
					// No Sessions for JTA transactions bound anymore -> could remove it. 
					TransactionSynchronizationManager.unbindResourceIfPossible(this.sessionFactory);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMessage, getSQL, getSQLException
	 * @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 operation: " + ex.getMessage(), ex.getSQL(), ex.getSQLException()); 
	} 
 
	/** 
	 * Convert the given SQLException to an appropriate exception from the 
	 * {@code org.springframework.dao} hierarchy. Can be overridden in subclasses. 
	 * <p>Note that a direct SQLException can just occur when callback code 
	 * performs direct JDBC access via {@code Session.connection()}. 
	 * @param ex the SQLException 
	 * @return the corresponding DataAccessException instance 
	 * @see #setJdbcExceptionTranslator 
	 */ 
	protected DataAccessException convertJdbcAccessException(SQLException ex) { 
		SQLExceptionTranslator translator = getJdbcExceptionTranslator(); 
		if (translator == null) { 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getSQL, getConstraintName
			PessimisticLockException jdbcEx = (PessimisticLockException) ex; 
			return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); 
		} 
		if (ex instanceof ConstraintViolationException) { 
			ConstraintViolationException jdbcEx = (ConstraintViolationException) ex; 
			return new DataIntegrityViolationException(ex.getMessage()  + "; SQL [" + jdbcEx.getSQL() + 
					"]; constraint [" + jdbcEx.getConstraintName() + "]", ex); 
		} 
		if (ex instanceof DataException) { 
			DataException jdbcEx = (DataException) ex; 
			return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); 
		} 
		if (ex instanceof JDBCException) { 
			return new HibernateJdbcException((JDBCException) ex); 
		} 
		// end of JDBCException (subclass) handling 
 
		if (ex instanceof QueryException) { 
			return new HibernateQueryException((QueryException) ex); 
		} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCause, getMessage, getSQL
		if (!(t instanceof JDBCException))
			return caster().toPageException(t);
		 
		 
		JDBCException j = (JDBCException)t;
		String message = j.getMessage(); 
		Throwable cause = j.getCause();
		if(cause != null) {
			message += " [" + cause.getMessage() + "]";
		} 
		return CFMLEngineFactory.getInstance().getExceptionUtil().createDatabaseException(message, new SQLImpl(j.getSQL()));
		 
	} 
	public static Serializable toSerializable(Object obj) throws PageException {
		return caster().toSerializable(obj); 
	} 
	public static Serializable toSerializable(Object obj,Serializable defaultValue) {
		return caster().toSerializable(obj,defaultValue);
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getErrorCode
			// expected result (if using versioned batching)... 
		} 
		catch( JDBCException e ) {
			// SQLServer will report this condition via a SQLException 
			// when using its SNAPSHOT transaction isolation... 
			if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) {
				throw e;
			} 
			else { 
				// it seems to "lose track" of the transaction as well... 
				mainSession.getTransaction().rollback();
				mainSession.beginTransaction();
			} 
		} 
		mainSession.clear();
		mainSession.getTransaction().commit();
		mainSession.close();
 
		mainSession = openSession();
		mainSession.beginTransaction();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Hibernate ORM JDBCException Methods: