Thomas Lang
Thomas Lang

Reputation: 1475

Validation of entities

Does Spring Data JDBC validate entities while persisting - as Spring Data JPA does with the help of hibernate?

I have this scenario:

Given this structure and assuming that Spring Data JDBC does no validation - I don´t need other annotations in the entities than @Id do I?

Upvotes: 2

Views: 1530

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81950

Spring Data JDBC does no validation.

It also won't in the future, because validation is an orthogonal concern to persistence.

And yes, in the described case an @Id annotation might be all that you need. Although I'd recommend to have a column using @Version to enable optimistic locking.

I'm not a big fan of Bean Validation. Validation should happen in the constructor so that it is not possible to create an invalid object in the first place. This is supported by Spring Data JDBC since it supports non-trivial constructors.

Upvotes: 3

Related Questions