Package org.hibernate.exception

Examples of org.hibernate.exception.ConstraintViolationException


    else if ( DataTruncation.class.isInstance( sqlException ) ||
        SQLDataException.class.isInstance( sqlException ) ) {
      throw new DataException( message, sqlException, sql );
    }
    else if ( SQLIntegrityConstraintViolationException.class.isInstance( sqlException ) ) {
      return new ConstraintViolationException(
          message,
          sqlException,
          sql,
          getConversionContext().getViolatedConstraintNameExtracter().extractConstraintName( sqlException )
      );
View Full Code Here


        }
        else if ( INTEGRITY_VIOLATION_CATEGORIES.contains( sqlStateClassCode ) ) {
          final String constraintName = getConversionContext()
              .getViolatedConstraintNameExtracter()
              .extractConstraintName( sqlException );
          return new ConstraintViolationException( message, sqlException, sql, constraintName );
        }
        else if ( CONNECTION_CATEGORIES.contains( sqlStateClassCode ) ) {
          return new JDBCConnectionException( message, sqlException, sql );
        }
        else if ( DATA_CATEGORIES.contains( sqlStateClassCode ) ) {
View Full Code Here

    else if ( DataTruncation.class.isInstance( sqlException ) ||
        SQLDataException.class.isInstance( sqlException ) ) {
      throw new DataException( message, sqlException, sql );
    }
    else if ( SQLIntegrityConstraintViolationException.class.isInstance( sqlException ) ) {
      return new ConstraintViolationException(
          message,
          sqlException,
          sql,
          getConversionContext().getViolatedConstraintNameExtracter().extractConstraintName( sqlException )
      );
View Full Code Here

    }
    catch(SQLException sqle) {
      JDBCExceptionReporter.logExceptions(sqle, "Just output!!!!");
      JDBCException jdbcException = converter.convert(sqle, null, null);
      assertEquals( "Bad conversion [" + sqle.getMessage() + "]", ConstraintViolationException.class , jdbcException.getClass() );
      ConstraintViolationException ex = (ConstraintViolationException) jdbcException;
      System.out.println("Violated constraint name: " + ex.getConstraintName());
    }
    finally {
      if ( ps != null ) {
        try {
          ps.close();
View Full Code Here

    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 JDBCException) {
      return new HibernateJdbcException((JDBCException) ex);
    }
    if (ex instanceof PropertyValueException) {
View Full Code Here

    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 JDBCException) {
      return new HibernateJdbcException((JDBCException) ex);
    }
    if (ex instanceof PropertyValueException) {
View Full Code Here

      GenericJDBCException jdbcEx = new GenericJDBCException("mymsg", sqlEx);
      txControl.setThrowable(jdbcEx, 1);
      rootCause = sqlEx;
    }
    else {
      ConstraintViolationException jdbcEx = new ConstraintViolationException("mymsg", sqlEx, null);
      txControl.setThrowable(jdbcEx, 1);
      rootCause = jdbcEx;
    }
    session.close();
    sessionControl.setReturnValue(null, 1);
View Full Code Here

    sfControl.setReturnValue(session, 1);
    session.getSessionFactory();
    sessionControl.setReturnValue(sf, 1);
    SQLException sqlEx = new SQLException("argh", "27");
    session.flush();
    ConstraintViolationException jdbcEx = new ConstraintViolationException("", sqlEx, null);
    sessionControl.setThrowable(jdbcEx, 1);
    session.close();
    sessionControl.setReturnValue(null, 1);
    sfControl.replay();
    sessionControl.replay();
View Full Code Here

      // expected
      assertEquals(laex, ex.getCause());
      assertTrue(ex.getMessage().indexOf("mymsg") != -1);
    }

    final ConstraintViolationException cvex = new ConstraintViolationException("mymsg", sqlEx, "myconstraint");
    try {
      createTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(org.hibernate.Session session) throws HibernateException {
          throw cvex;
        }
View Full Code Here

                    }

          if ( 90006 == errorCode ) {
            // NULL not allowed for column [90006-145]
            final String constraintName = getViolatedConstraintNameExtracter().extractConstraintName( sqlException );
            exception = new ConstraintViolationException( message, sqlException, sql, constraintName );
          }

          return exception;
        }
      };
View Full Code Here

TOP

Related Classes of org.hibernate.exception.ConstraintViolationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.