List of usage examples for org.hibernate.exception ConstraintViolationException getSQLException
public SQLException getSQLException()
From source file:com.vmware.photon.controller.apife.db.dao.ImageDaoTest.java
License:Open Source License
@Test public void testNullReplicationType() { ImageEntity image = new ImageEntity(); image.setReplicationType(null);//from w w w.j a v a2 s . co m imageDao.create(image); try { flushSession(); fail("should fail to set replication type to null"); } catch (ConstraintViolationException e) { assertThat(e.getSQLException().getMessage(), startsWith("NULL not allowed for column \"REPLICATION_TYPE\"")); } }
From source file:de.dfki.asr.compass.business.exception.PersistenceException.java
License:Apache License
private static String processHibernateConstraintViolationExceptionMessage( final ConstraintViolationException ex) { String detail = ex.getSQLException().getMessage(); String msg = "Could not process entity: Database constraint violation."; if (detail.contains("FOREIGN KEY")) { msg = "Could not process entity: One or more referenced entities do not exist."; } else if (detail.contains("UNIQUE KEY")) { msg = "Could not process entity: A duplicate name already exists, please choose another."; }//from ww w . j a v a2 s . co m return msg; }
From source file:es.logongas.ix3.dao.impl.ExceptionTranslator.java
License:Apache License
public List<BusinessMessage> getBusinessMessages(org.hibernate.exception.ConstraintViolationException cve) { List<BusinessMessage> businessMessages = new ArrayList<BusinessMessage>(); BusinessMessage businessMessage;// w w w .j av a 2s . co m String message; int errorCode; String sqlState; if (cve.getSQLException() != null) { message = cve.getSQLException().getLocalizedMessage(); errorCode = cve.getSQLException().getErrorCode(); sqlState = cve.getSQLException().getSQLState(); } else { message = cve.getLocalizedMessage(); errorCode = cve.getErrorCode(); sqlState = cve.getSQLState(); } es.logongas.ix3.core.database.ConstraintViolation constraintViolation = constraintViolationTranslator .translate(message, errorCode, sqlState); if (constraintViolation == null) { throw cve; } else { businessMessage = new BusinessMessage(constraintViolation.getMessage()); } businessMessages.add(businessMessage); return businessMessages; }
From source file:jcms.integrationtier.exception.ConstraintViolationExceptionMySqlPatch.java
License:Open Source License
public ConstraintViolationExceptionMySqlPatch(ConstraintViolationException cve) { super(cve.getMessage(), cve.getSQLException(), cve.getSQL(), cve.getConstraintName()); this.constraintName = extractConstraintName(); }
From source file:org.openbravo.service.db.DbUtility.java
License:Open Source License
/** * This method will take care of finding the real underlying exception. When a jdbc or hibernate * exception occurs then the whole stack trace is not available in the log because the exception * does not return the underlying exception using the {@link Throwable#getCause()} but using the * {@link SQLException#getNextException()}. * /*from w w w .jav a 2 s . c o m*/ * @param throwable * the throwable to analyze * @return the underlying sql exception or the original throwable if none found */ public static Throwable getUnderlyingSQLException(Throwable throwable) { if (throwable.getCause() instanceof BatchUpdateException && ((BatchUpdateException) throwable.getCause()).getNextException() != null) { final BatchUpdateException bue = (BatchUpdateException) throwable.getCause(); return bue.getNextException(); } if (throwable.getCause() instanceof org.hibernate.exception.GenericJDBCException && ((org.hibernate.exception.GenericJDBCException) throwable.getCause()).getSQLException() .getNextException() != null) { final org.hibernate.exception.GenericJDBCException gjdbce = (org.hibernate.exception.GenericJDBCException) throwable .getCause(); return gjdbce.getSQLException().getNextException(); } if (throwable.getCause() instanceof org.hibernate.exception.ConstraintViolationException && ((org.hibernate.exception.ConstraintViolationException) throwable.getCause()).getSQLException() .getNextException() != null) { final org.hibernate.exception.ConstraintViolationException cve = (org.hibernate.exception.ConstraintViolationException) throwable .getCause(); return cve.getSQLException().getNextException(); } return throwable; }
From source file:org.openeos.services.ui.internal.PostgreSQLDialectBatchUpdateResolver.java
License:Apache License
@Override protected Throwable unencapsuleThrowable(Throwable t) { if (t instanceof ConstraintViolationException) { ConstraintViolationException constrainEx = (ConstraintViolationException) t; if (constrainEx.getConstraintName() == null) { SQLException sqlEx = constrainEx.getSQLException(); if (sqlEx instanceof BatchUpdateException) { SQLException other = sqlEx.getNextException(); if (other != null) { String constraintName = conversionContext.getViolatedConstraintNameExtracter() .extractConstraintName(other); if (constraintName != null) { return new ConstraintViolationException(t.getMessage(), sqlEx, constraintName); }/* w ww . ja va 2s . c om*/ } } } } return null; }