Results 1 to 2 of 2

Thread: Spring throws JpaSystemException when using Hibernate Validator

  1. #1
    Join Date
    Jan 2009
    Posts
    5

    Default Spring throws JpaSystemException when using Hibernate Validator

    When I use Hibernate Validator (3.1.0 + 3.3.1 Core) with Spring (2.5.6) I can't catch the InvalidStateException directly. Spring throws a JpaSystemException, whose cause is a RollBackException, whose cause is finally the InvalidStateException. The same happens with PersistenceException and IllegalArgumentException at methods that I have implemented, like the following example:

    Code:
            @PrePersist
            @PreUpdate
            protected void prePersist(StReservaVeiculo reserva)
            {
                if(reserva.getKmInicial() != null && reserva.getKmFinal() != null &&
                    reserva.getKmInicial() > reserva.getKmFinal())
                {
                    throw new PersistenceException("KM inicial maior que KM final");
                }       
            }
    DAO:

    Code:
          @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
            public void persist(T t)
            {
               em.merge(t);
            }
    If add a call to EntityManager's flush() after merge(), I get the expected result, so I can catch the exceptions normally.

    Is this the best approach?

    Thanks,
    Felipe

  2. #2
    Join Date
    Jan 2009
    Posts
    5

    Default

    ...
    Anyone?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •