When using NetBeans 7 to generate entity classes from a database table, the entity classes are generated with the following annotations...
When persisting, bean validation fails because the autogenerated primary key is null at the time the object is persisted.
Netbeans have stated that they wont fix this as they see it as bean validation issue rather than their generated classes.
Related Forum posting is here...
Suggest modifying Bean Validation Pre-Persist to ignore @NotNull if @GeneratedValue exists.
Netbeans 7, Seam 3 under JBOSS AS 7
I'll raise the issue with the JPA expert group but I am not certain I agree with the NetBeans team on this.
Even if right, how do ignore @NotNull when JPA's provider calls Bean Validation? A generic contract to ignore some constraint annotations based on property name?
FYI: I commented in NetBeans issue why I think this should be resolved on JPA side - http://netbeans.org/bugzilla/show_bug.cgi?id=197845#c3
It is possible I'm completely wrong here as spec is not very clear to me. Until we reach a consensus I suggest NetBeans do not generate @NotNull constraint as it is causing more harm than help.
Let's experiment with before moving it up at the spec levels.