Announcement Announcement Module
Collapse
No announcement yet.
Spring throws JpaSystemException when using Hibernate Validator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    ...
    Anyone?

    Comment

    Working...
    X