List of usage examples for org.hibernate JDBCException getSQL
public String getSQL()
From source file:com.opensymphony.able.filter.SimpleTransactionServletFilter.java
License:Apache License
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain filterChain) throws IOException, ServletException { // TODO we could get clever and figure out what URIs are read only transactions etc final TransactionTemplate transactionTemplate = (TransactionTemplate) context .getBean("transactionTemplate"); transactionTemplate.setReadOnly(false); if (log.isDebugEnabled()) { log.debug("Starting a transaction"); }/*w w w . j a va 2 s . c om*/ try { Exception e = (Exception) transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { try { TransactionOutcome outcome = new TransactionOutcome(status, transactionTemplate); TransactionOutcome.setTransactionOutcome(outcome); filterChain.doFilter(request, response); if (outcome.isRollbackOnly()) { log.debug("Outcome is rollback"); status.setRollbackOnly(); } if (log.isDebugEnabled()) { log.debug("Completing a transaction with rollback: " + status.isRollbackOnly()); } return null; } catch (RuntimeException e) { throw e; } catch (Exception e) { return e; } } }); if (log.isDebugEnabled()) { log.debug("End transaction with exception: " + e); } if (e instanceof IOException) { throw (IOException) e; } else if (e instanceof ServletException) { throw (ServletException) e; } else if (e != null) { throw new ServletException(e); } } catch (TransactionException e) { Throwable cause = e.getCause(); if (cause.getCause() != null) { cause = cause.getCause(); } ; if (cause instanceof JDBCException) { JDBCException jdbcException = (JDBCException) cause; SQLException sqlException = jdbcException.getSQLException(); throw new ServletException("Failed to execute: " + jdbcException.getSQL() + ": error: " + sqlException.getSQLState() + ". Reason: " + sqlException, sqlException); } throw new ServletException(cause); } finally { TransactionOutcome.setTransactionOutcome(null); } }
From source file:de.decidr.test.database.main.TestDataGenerator.java
License:Apache License
/** * Runs the program (with "error handling") *///from w w w . jav a 2s . com private void run() { try { doRun(); } catch (Throwable e) { stdErr("An error occurred! Stack trace:"); e.printStackTrace(System.err); while (e.getCause() != null) { e = e.getCause(); if (e instanceof JDBCException) { JDBCException jdbcException = (JDBCException) e; stdErr("Statement that caused the exception:"); stdErr(jdbcException.getSQL()); } } } }
From source file:lucee.runtime.orm.hibernate.CommonUtil.java
License:Open Source License
public static PageException toPageException(Throwable t) { PageException pe = caster().toPageException(t); ;/*from ww w. j a v a2s.c om*/ if (t instanceof org.hibernate.HibernateException) { org.hibernate.HibernateException he = (org.hibernate.HibernateException) t; Throwable cause = he.getCause(); if (cause != null) { pe = caster().toPageException(cause); ExceptionUtil.setAdditional(pe, CommonUtil.createKey("hibernate exception"), t); } } if (t instanceof JDBCException) { JDBCException je = (JDBCException) t; ExceptionUtil.setAdditional(pe, CommonUtil.createKey("sql"), je.getSQL()); } if (t instanceof ConstraintViolationException) { ConstraintViolationException cve = (ConstraintViolationException) t; if (!Util.isEmpty(cve.getConstraintName())) { ExceptionUtil.setAdditional(pe, CommonUtil.createKey("constraint name"), cve.getConstraintName()); } } return pe; }
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./*w ww. j ava 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 w ww . j av a 2s . co m 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(); SQLException sqlException = ex.getSQLException(); return translator.translate("Hibernate operation: " + msg, sql, sqlException); }
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// w w w.j av a 2 s . 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.HibernateJdbcException.java
License:Apache License
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); }
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 ww w .jav a 2 s. c o m*/ return SessionFactoryUtils.convertHibernateAccessException(ex); }
From source file:org.transitime.db.structs.Block.java
License:Open Source License
/** * Uses lazy initialization to determine the trips for the block. * /*from w w w . j a v a 2 s. c om*/ * @return the trips */ public List<Trip> getTrips() { // It appears that lazy initialization is problematic when have multiple // simultaneous threads. Get "org.hibernate.AssertionFailure: force // initialize loading collection". Therefore need to make sure that // only loading lazy sub-data serially. Since it is desirable to have // trips collection be lazy loaded so that app starts right away without // loading all the sub-data for every block assignment need to make // sure this is done in a serialized way. Having app not load all data // at startup is especially important when debugging. if (!Hibernate.isInitialized(trips)) { // trips not yet initialized so synchronize so only a single // thread can initialize at once and then access something // in trips that will cause it to be lazy loaded. synchronized (lazyLoadingSyncObject) { logger.debug("About to do lazy load for trips data for " + "blockId={} serviceId={}...", blockId, serviceId); IntervalTimer timer = new IntervalTimer(); // Access the collection so that it is lazy loaded. // Problems can be difficult to debug so log error along // with the SQL. try { trips.get(0); } catch (JDBCException e) { logger.error("In Block.getTrips() got JDBCException. " + "SQL=\"{}\" msg={}", e.getSQL(), e.getSQLException().getMessage()); throw e; } logger.debug("Finished lazy load for trips data for " + "blockId={} serviceId={}. Took {} msec", blockId, serviceId, timer.elapsedMsec()); } } return Collections.unmodifiableList(trips); }