Package org.hibernate.exception

Examples of org.hibernate.exception.ConstraintViolationException


      GenericJDBCException jdbcEx = new GenericJDBCException("mymsg", sqlEx);
      rootCause = sqlEx;
      willThrow(jdbcEx).given(tx).commit();
    }
    else {
      ConstraintViolationException jdbcEx = new ConstraintViolationException("mymsg", sqlEx, null);
      rootCause = jdbcEx;
      willThrow(jdbcEx).given(tx).commit();
    }
    given(session.isConnected()).willReturn(true);
    given(session.connection()).willReturn(con);
View Full Code Here


      // expected
      assertEquals(laex, ex.getCause());
      assertTrue(ex.getMessage().contains("mymsg"));
    }

    final ConstraintViolationException cvex = new ConstraintViolationException("mymsg", sqlEx, "myconstraint");
    try {
      hibernateTemplate.execute(new HibernateCallback<Object>() {
        @Override
        public Object doInHibernate(Session session)  {
          throw cvex;
View Full Code Here

    given(sf.openSession()).willReturn(session);
    given(session.beginTransaction()).willReturn(tx);
    given(session.isOpen()).willReturn(true);
    SQLException sqlEx = new SQLException("argh", "27");
    Exception rootCause = null;
    ConstraintViolationException jdbcEx = new ConstraintViolationException("mymsg", sqlEx, null);
    rootCause = jdbcEx;
    willThrow(jdbcEx).given(tx).commit();
    given(session.isConnected()).willReturn(true);
    given(session.connection()).willReturn(con);
View Full Code Here

    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
View Full Code Here

  }

  @Test
  public void testInterceptorWithFlushFailure() throws Throwable {
    SQLException sqlEx = new SQLException("argh", "27");
    ConstraintViolationException jdbcEx = new ConstraintViolationException("", sqlEx, null);
    willThrow(jdbcEx).given(session).flush();

    HibernateInterceptor interceptor = new HibernateInterceptor();
    interceptor.setSessionFactory(sessionFactory);
    try {
View Full Code Here

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

    final ConstraintViolationException cvex = new ConstraintViolationException("mymsg", sqlEx, "myconstraint");
    try {
      hibernateTemplate.execute(new HibernateCallback<Object>() {
        @Override
        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

   */
  @Override
  public ActionForward execute(Exception exception, ExceptionConfig arg1, ActionMapping mapping, ActionForm arg3, HttpServletRequest req, HttpServletResponse arg5) throws ServletException {
    String userName = req.getUserPrincipal() == null ? "`ANONYMOUS USER`" : req.getUserPrincipal().getName().toLowerCase();   
    correctStrutsLocale(req);
    ConstraintViolationException e = (ConstraintViolationException) exception;
    LOGGER.error("user " + userName + ": ",e);
    return mapping.findForward("constraintViolationErrorPage");
  }
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

    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

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.