0

I have a JPA model class, which worked as I expected it. A few weeks ago it started throwing errors and failed to persist.

javax.persistence.RollbackException: 
  javax.validation.ConstraintViolationException: 
    One or more Bean Validation constraints were 
    violated while executing Automatic Bean Validation
    on callback event: preUpdate

I extracted the ConstraintViolation, which stated:

must be greater or equal 0.01

This led me to the only attribute annotated with @DecimalMin in my model:

@Column(nullable = false, precision = 36, scale = 2)
@DecimalMin("0.01")
@NonNull
private BigDecimal amount;

So far this sounds reasonable, but the strange thing is, the exception is raised always, no matter the value of amount. I tried it with an amount of 1.00 and still got the exception.

The only other clue I have is in the database, where 0.00 was persisted as the last value for amount. I neither know how this was possible nor if it has to do with my problem.


Edit

The comments under this questions raised the need for me to clarify the environment. The database is deployed on the customers side, but he has no access to it. The schema is application exclusive and the credentials are encrypted. Therefore nobody, but the application should have been able to access the database.

The application itself is divided into an API module and a UI module. Both use the same core module for database access. The model is also part of the core module and used by the other two modules. The API is deployed on a server and allows strongly restricted access to only few operations. It is only used for other applications to integrate. The UI is installed at the clients machine and allows access to more features.

The amount of 0.00 in the database originated from the UI application. Since that moment any try to use the same operation via the API failed, whereas the UI application still works as expected.

All modules are versioned and build together in a single build process and I did ensure, that all versions on all clients are the same.

tgr
  • 3,557
  • 4
  • 33
  • 63
  • I'd assume because you set nullable to false, the db will always insert 0.00 as default -> constraint violation – DGK Feb 12 '19 at 07:08
  • Well, the value must originate from my model class, because there are other fields, that cannot be set from the database (OracleDB cannot create a `UUID`). Therefore I can rule out this possibility. – tgr Feb 12 '19 at 07:18
  • 2
    FYI That is the Bean Validation API, not the JPA API –  Feb 12 '19 at 07:22
  • The point of the tag was, to state, what technologies are used. So this question can be found by experts in this field. Besides the JPA tag referred to the problems context. I nevertheless approved of your edit. – tgr Feb 12 '19 at 08:08
  • You have ruled it out but have you tested it? Does the exception occur when you set DecimalMin to 0.00 – DGK Feb 12 '19 at 08:25
  • If you see 0.00 in the database, you need to analyze how it got there - make sure that other applications (or even someone manually using SQLPlus or other DB tool) didn't access and modify a row outside your application. For the next issue you have, are you getting this exception when modifying entities that have 0.00 in the database? It might be that your bean-validator is running before or during a merge operation and so throwing an exception off of the value in the database. – Chris Feb 13 '19 at 17:09

0 Answers0