List of usage examples for org.hibernate.exception SQLGrammarException getSQL
public String getSQL()
From source file:motor.MOTOR.java
/** * Mtodo que inserta una registro en la tabla cliente. Utiliza operaciones * elementales/*from w w w .j a v a 2 s . c om*/ * * @param cliente el coche a insertar * @throws ExceptionMotor excepcion que integra el mensaje de error al * usuario, el codigo de error y el mensaje de error que nos ha devuelto la * base de datos. */ public void insertarCliente(Cliente cliente) throws ExceptionMotor { // Se inicia una transaccin en la sesin creada Transaction t = sesion.beginTransaction(); try { sesion.save(cliente); // Se confirma la transaccin t.commit(); } catch (IdentifierGenerationException igEx) { ExceptionMotor ex = new ExceptionMotor(); throw ex; } catch (ConstraintViolationException igEx) { ExceptionMotor ex = new ExceptionMotor(); if (igEx.getErrorCode() == 2290) { ex.setCodigoErrorAdministrador(igEx.getErrorCode()); ex.setSentenciaSQL(igEx.getSQL()); ex.setMensajeErrorUsuario( "Error. El campo telefono debe empezar por 6 o 9 y contener 9 caracteres numricos y el email debe acabar en .com o .es"); ex.setMensajeErrorAdministrador(igEx.getMessage()); } else { ex.setCodigoErrorAdministrador(igEx.getErrorCode()); ex.setSentenciaSQL(igEx.getSQL()); ex.setMensajeErrorUsuario("Error. Los siguientes campos son nicos: dni, email y telefono"); ex.setMensajeErrorAdministrador(igEx.getMessage()); } throw ex; } catch (PropertyValueException pvEx) { ExceptionMotor ex = new ExceptionMotor(); ex.setMensajeErrorUsuario( "Error. Los siguientes campos son obligatorios: nombre, apellido1, email, telefono, dni"); ex.setMensajeErrorAdministrador(pvEx.getMessage()); throw ex; } catch (SQLGrammarException sqlEx) { ExceptionMotor ex = new ExceptionMotor(); ex.setCodigoErrorAdministrador(sqlEx.getErrorCode()); ex.setSentenciaSQL(sqlEx.getSQL()); ex.setMensajeErrorUsuario("Error. El campo telefono es un campo numerico"); ex.setMensajeErrorAdministrador(sqlEx.getMessage()); throw ex; } catch (GenericJDBCException jdbcEx) { ExceptionMotor ex = new ExceptionMotor(); if (jdbcEx.getErrorCode() == 20004) { ex.setCodigoErrorAdministrador(jdbcEx.getErrorCode()); ex.setSentenciaSQL(jdbcEx.getSQL()); ex.setMensajeErrorUsuario("Error. El taller esta cerrado"); ex.setMensajeErrorAdministrador(jdbcEx.getMessage()); } if (jdbcEx.getErrorCode() == 20005) { ex.setCodigoErrorAdministrador(jdbcEx.getErrorCode()); ex.setSentenciaSQL(jdbcEx.getSQL()); ex.setMensajeErrorUsuario("Error. El email debe acabar por .com o .es"); ex.setMensajeErrorAdministrador(jdbcEx.getMessage()); } if (jdbcEx.getErrorCode() == 20006) { ex.setCodigoErrorAdministrador(jdbcEx.getErrorCode()); ex.setSentenciaSQL(jdbcEx.getSQL()); ex.setMensajeErrorUsuario("Error. El campo telefono es un campo numerico de 9 caracteres"); ex.setMensajeErrorAdministrador(jdbcEx.getMessage()); } throw ex; } catch (Exception e) { ExceptionMotor ex = new ExceptionMotor(); ex.setCodigoErrorAdministrador(0); ex.setMensajeErrorUsuario("Error general en el sistema, Consulte con el administrador"); ex.setMensajeErrorAdministrador(e.getMessage()); throw ex; } }
From source file:motor.MOTOR.java
/** * Mtodo que modifica los registros de un cliente ya existente. Utiliza * operaciones elementales/*from w w w . jav a 2 s.c o m*/ * * @param cliente los datos del coche a modificar * @throws ExceptionMotor excepcion que integra el mensaje de error al * usuario, el codigo de error y el mensaje de error que nos ha devuelto la * base de datos */ public void modificarCliente(Cliente cliente) throws ExceptionMotor { Transaction t = sesion.beginTransaction(); try { sesion.update(cliente); // Se confirma la transaccin t.commit(); } catch (ConstraintViolationException cvEx) { ExceptionMotor ex = new ExceptionMotor(); if (cvEx.getErrorCode() == 2290) { ex.setCodigoErrorAdministrador(cvEx.getErrorCode()); ex.setSentenciaSQL(cvEx.getSQL()); ex.setMensajeErrorUsuario( "Error. El campo telefono debe empezar por 6 o 9 y contener 9 caracteres numricos y el email debe acabar en .com o .es"); ex.setMensajeErrorAdministrador(cvEx.getMessage()); } else { ex.setCodigoErrorAdministrador(cvEx.getErrorCode()); ex.setSentenciaSQL(cvEx.getSQL()); ex.setMensajeErrorUsuario("Error. Los siguientes campos son unicos: dni, email y telefono"); ex.setMensajeErrorAdministrador(cvEx.getMessage()); } throw ex; } catch (PropertyValueException pvEx) { ExceptionMotor ex = new ExceptionMotor(); ex.setMensajeErrorUsuario( "Error. Los siguientes campos son obligatorios: nombre, apellido1, email, telefono, dni"); ex.setMensajeErrorAdministrador(pvEx.getMessage()); throw ex; } catch (SQLGrammarException sqlEx) { ExceptionMotor ex = new ExceptionMotor(); ex.setCodigoErrorAdministrador(sqlEx.getErrorCode()); ex.setSentenciaSQL(sqlEx.getSQL()); ex.setMensajeErrorUsuario("Error. El telefono es un campo numerico"); ex.setMensajeErrorAdministrador(sqlEx.getMessage()); throw ex; } catch (GenericJDBCException jdbcEx) { ExceptionMotor ex = new ExceptionMotor(); if (jdbcEx.getErrorCode() == 20004) { ex.setCodigoErrorAdministrador(jdbcEx.getErrorCode()); ex.setSentenciaSQL(jdbcEx.getSQL()); ex.setMensajeErrorUsuario("Error. El taller esta cerrado"); ex.setMensajeErrorAdministrador(jdbcEx.getMessage()); } if (jdbcEx.getErrorCode() == 20005) { ex.setCodigoErrorAdministrador(jdbcEx.getErrorCode()); ex.setSentenciaSQL(jdbcEx.getSQL()); ex.setMensajeErrorUsuario("Error. El email debe acabar por .com o .es"); ex.setMensajeErrorAdministrador(jdbcEx.getMessage()); } if (jdbcEx.getErrorCode() == 20006) { ex.setCodigoErrorAdministrador(jdbcEx.getErrorCode()); ex.setSentenciaSQL(jdbcEx.getSQL()); ex.setMensajeErrorUsuario("Error. El campo telefono es un campo numerico de 9 caracteres"); ex.setMensajeErrorAdministrador(jdbcEx.getMessage()); } throw ex; } catch (StaleStateException ssEx) { ExceptionMotor ex = new ExceptionMotor(); ex.setMensajeErrorUsuario("Error. No existe ese cliente"); throw ex; } catch (Exception e) { ExceptionMotor ex = new ExceptionMotor(); ex.setCodigoErrorAdministrador(0); ex.setMensajeErrorUsuario("Error general en el sistema, Consulte con el administrador"); ex.setMensajeErrorAdministrador(e.getMessage()); throw ex; } }
From source file:org.beangle.commons.orm.hibernate.internal.SessionUtils.java
License:Open Source License
@SuppressWarnings("serial") public static DataAccessException convertHibernateAccessException(HibernateException ex) { if (ex instanceof JDBCConnectionException) { return new DataAccessResourceFailureException(ex.getMessage(), ex); }//from w ww.ja va2s .co m if (ex instanceof SQLGrammarException) { SQLGrammarException jdbcEx = (SQLGrammarException) ex; return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof LockAcquisitionException) { LockAcquisitionException jdbcEx = (LockAcquisitionException) ex; return new CannotAcquireLockException(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 PropertyValueException) { return new DataIntegrityViolationException(ex.getMessage(), ex); } if (ex instanceof PersistentObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof TransientObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof ObjectDeletedException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } return new UncategorizedDataAccessException(ex.getMessage(), ex) { }; }
From source file:org.beangle.orm.hibernate.internal.SessionUtils.java
License:Open Source License
@SuppressWarnings("serial") public static DataAccessException convertHibernateAccessException(HibernateException ex) { if (ex instanceof JDBCConnectionException) { return new DataAccessResourceFailureException(ex.getMessage(), ex); }//w w w . ja v a 2 s . c o m if (ex instanceof SQLGrammarException) { SQLGrammarException jdbcEx = (SQLGrammarException) ex; return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof LockAcquisitionException) { LockAcquisitionException jdbcEx = (LockAcquisitionException) ex; return new CannotAcquireLockException(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 NonUniqueResultException) { return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex); } if (ex instanceof NonUniqueObjectException) { return new DuplicateKeyException(ex.getMessage(), ex); } if (ex instanceof PropertyValueException) { return new DataIntegrityViolationException(ex.getMessage(), ex); } if (ex instanceof PersistentObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof TransientObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof ObjectDeletedException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } return new UncategorizedDataAccessException(ex.getMessage(), ex) { }; }
From source file:org.openhie.openempi.loader.AbstractFileLoader.java
License:Open Source License
public void loadPerson(Person person) { log.debug("Attempting to load person entry " + person); try {/* w w w . j a v a2 s. c o m*/ Boolean previewOnly = (Boolean) getParameter(PREVIEW_ONLY); if (previewOnly == null || !previewOnly.booleanValue()) { personManager.addPerson(person); } } catch (Exception e) { log.error("Failed while adding person entry to the system. Error: " + e, e); if (e.getCause() instanceof org.hibernate.exception.SQLGrammarException) { org.hibernate.exception.SQLGrammarException sge = (org.hibernate.exception.SQLGrammarException) e; log.error("Cause is: " + sge.getSQL()); } } }
From source file:org.openhie.openempi.loader.AbstractLoaderBase.java
License:Apache License
public boolean loadPerson(String tableName, Person person, boolean applyFieldTransformations) { log.debug("Attempting to load person entry " + person); contributePersonToStatistics(person); try {/* w w w .ja v a2 s . c o m*/ personManagerService.addPerson(tableName, person, applyFieldTransformations, false); } catch (Exception e) { log.error("Failed while adding person entry to the system. Error: " + e, e); if (e.getCause() instanceof org.hibernate.exception.SQLGrammarException) { org.hibernate.exception.SQLGrammarException sge = (org.hibernate.exception.SQLGrammarException) e; log.error("Cause is: " + sge.getSQL()); } // throw new RuntimeException("Failed while adding person entry to the system."); return false; } return true; }
From source file:org.openhie.openempi.loader.AbstractLoaderBase.java
License:Apache License
public boolean loadPersons(String tableName, List<Person> persons, boolean applyFieldTransformations) { log.debug("Attempting to load persons (" + persons.size() + ")"); try {/*from w w w .j a va 2 s. com*/ personManagerService.addPersons(tableName, persons, applyFieldTransformations, false); } catch (Exception e) { log.error("Failed while adding person entry to the system. Error: " + e, e); if (e.getCause() instanceof org.hibernate.exception.SQLGrammarException) { org.hibernate.exception.SQLGrammarException sge = (org.hibernate.exception.SQLGrammarException) e; log.error("Cause is: " + sge.getSQL()); } // throw new RuntimeException("Failed while adding person entry to the system."); return false; } return true; }
From source file:org.openhie.openempi.loader.concurrent.RecordLoaderTask.java
License:Open Source License
public void run() { log.debug("With User Context: " + userContext + " attempting to load entry record" + record); Context.setUserContext(userContext); try {// w w w . j a v a2 s.com synchronized (userContext) { Record theRecord = entityLoaderManager.addRecord(entity, record); if (key != null) { // generateKnownLinks(key, record); } } } catch (Exception e) { log.error("Failed while adding entity entry to the system. Error: " + e, e); if (e.getCause() instanceof org.hibernate.exception.SQLGrammarException) { org.hibernate.exception.SQLGrammarException sge = (org.hibernate.exception.SQLGrammarException) e; log.error("Cause is: " + sge.getSQL()); } } }
From source file:org.openhie.openempi.loader.RecordLoaderTask.java
License:Open Source License
public void run() { log.debug("With User Context: " + userContext + " attempting to load person entry " + person); Context.setUserContext(userContext); try {// w w w . j a v a 2s. co m personLoaderManager.addPerson(person); } catch (Exception e) { log.error("Failed while adding person entry to the system. Error: " + e, e); if (e.getCause() instanceof org.hibernate.exception.SQLGrammarException) { org.hibernate.exception.SQLGrammarException sge = (org.hibernate.exception.SQLGrammarException) e; log.error("Cause is: " + sge.getSQL()); } } }
From source file:org.springframework.orm.hibernate3.SessionFactoryUtils.java
License:Apache License
/** * Convert the given HibernateException to an appropriate exception * from the {@code org.springframework.dao} hierarchy. * @param ex HibernateException that occurred * @return the corresponding DataAccessException instance * @see HibernateAccessor#convertHibernateAccessException * @see HibernateTransactionManager#convertHibernateAccessException */// w ww. j a v a 2 s .c o m public static DataAccessException convertHibernateAccessException(HibernateException ex) { if (ex instanceof JDBCConnectionException) { return new DataAccessResourceFailureException(ex.getMessage(), ex); } if (ex instanceof SQLGrammarException) { SQLGrammarException jdbcEx = (SQLGrammarException) ex; return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof QueryTimeoutException) { QueryTimeoutException jdbcEx = (QueryTimeoutException) ex; return new org.springframework.dao.QueryTimeoutException( ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof LockAcquisitionException) { LockAcquisitionException jdbcEx = (LockAcquisitionException) ex; return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof PessimisticLockException) { 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); } if (ex instanceof NonUniqueResultException) { return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex); } if (ex instanceof NonUniqueObjectException) { return new DuplicateKeyException(ex.getMessage(), ex); } if (ex instanceof PropertyValueException) { return new DataIntegrityViolationException(ex.getMessage(), ex); } if (ex instanceof PersistentObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof TransientObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof ObjectDeletedException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof UnresolvableObjectException) { return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex); } if (ex instanceof WrongClassException) { return new HibernateObjectRetrievalFailureException((WrongClassException) ex); } if (ex instanceof StaleObjectStateException) { return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex); } if (ex instanceof StaleStateException) { return new HibernateOptimisticLockingFailureException((StaleStateException) ex); } if (ex instanceof OptimisticLockException) { return new HibernateOptimisticLockingFailureException((OptimisticLockException) ex); } // fallback return new HibernateSystemException(ex); }