Add support for JSR303 (Bean validation) annotations.
Right now, JPA spec neglect Bean Validation annotations.
The way it is now we end with duplicated information:
@Column(nullable = false, length = 200)
@NotNull
@Size(min = 4, max = 200)
private String name;
Would be nice just do:
@Column
@NotNull
@Size(min = 4, max = 200)
private String name;
and end with same result.
- Issue Imported From: https://github.com/javaee/jpa-spec/issues/34
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @ldemichiel
@glassfishrobot Commented Reported by velobr
@glassfishrobot Commented @ldemichiel said: Actually, result is not the same, because Bean Validation will trap the constraint validation before it goes to the database. I think what you may be asking for is integration of Bean Validation constraints into the schema generation facility. There has not been strong support for this, but it is something that we could consider in a future release.
@glassfishrobot Commented c.beikov said: I think that this is also related to #23 If a "PhysicalCustomizer" as mentioned in the comments could alter the column definition we could even translate annotations to domain constraints by ourselves. I guess what we really need here is an abstraction that enables us to enrich the meta- and physical model in general.
@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-34
I think the way things are right now is simple and allows for a clear separation of concerns. This proposal will find up being pretty convoluted. I suggest just closing this to reduce clutter.
Reza Rahman Jakarta EE Ambassador, Author, Blogger, Speaker
Please note views expressed here are my own as an individual community member and do not reflect the views of my employer.
The way it is now we end with duplicated information:
Well, I can't speak for other JPA implementations, but at least in Hibernate this is not the case: DDL generation respects the Validation annotations, as was always the intention of the people who wrote the Bean Validation spec. @emmanuelbernard
If there are other JPA implementations out there which don't respect the Bean Validation annotations in their DDL generation, then that's nothing more than a weakness in their implementation of DDL generation.
So this issue can surely be closed.
Section 3.6 of the specification deals with Bean Validation integration.
The spec itself does not really tightly constrain DDL generation. (And this is a good thing IMO.) So whether any particular implementation respects Bean Validation annotations is a question for the implementation. In our implementation, we do take these annotations into account.