mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-01 16:19:49 +00:00
Fix for Issue 34 - JSR 303 Validation groups are ignored for DDL
generation (of @NotNull)
This commit is contained in:
@@ -22,7 +22,6 @@ import javax.persistence.Transient;
|
||||
import javax.persistence.Version;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import com.avaje.ebean.annotation.CreatedTimestamp;
|
||||
import com.avaje.ebean.annotation.EmbeddedColumns;
|
||||
import com.avaje.ebean.annotation.Encrypted;
|
||||
@@ -193,9 +192,10 @@ public class AnnotationFields extends AnnotationParser {
|
||||
|
||||
if (validationAnnotations) {
|
||||
NotNull notNull = get(prop, NotNull.class);
|
||||
if (notNull != null) {
|
||||
// explicitly specify a version column
|
||||
prop.setNullable(false);
|
||||
if (notNull != null && isNotNullOnAllValidationGroups(notNull.groups())) {
|
||||
// Not null on all validation groups so enable
|
||||
// DDL generation of Not Null Constraint
|
||||
prop.setNullable(false);
|
||||
}
|
||||
|
||||
Size size = get(prop, Size.class);
|
||||
@@ -255,6 +255,20 @@ public class AnnotationFields extends AnnotationParser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the validation is on all validation groups and hence
|
||||
* can be applied to DDL generation.
|
||||
*/
|
||||
private boolean isNotNullOnAllValidationGroups(Class<?>[] groups) {
|
||||
if (groups.length == 0) {
|
||||
return true;
|
||||
}
|
||||
if (groups.length == 1 && javax.validation.groups.Default.class.isAssignableFrom(groups[0])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setEncryption(DeployBeanProperty prop, boolean dbEncString, int dbLen) {
|
||||
|
||||
util.checkEncryptKeyManagerDefined(prop.getFullBeanName());
|
||||
|
||||
Reference in New Issue
Block a user