From 5aed178b35fd2f4dc98be77ed756ee3dc971a757 Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Thu, 11 Nov 2010 17:30:34 +0100 Subject: [PATCH] HV-361 Taking into account that applyDDL can be called multiple times. Adding comment that @Range annotation is automatically taken care of, because it is a composing constraint of @Min and @Max --- .../cfg/beanvalidation/TypeSafeActivator.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java b/core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java index 58f682c454..336af8ad28 100644 --- a/core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java +++ b/core/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java @@ -172,7 +172,9 @@ private static void applyDDL(String prefix, private static boolean applyConstraints(Set> constraintDescriptors, Property property, PropertyDescriptor propertyDesc, - Set> groups, boolean canApplyNotNull) { + Set> groups, + boolean canApplyNotNull + ) { boolean hasNotNull = false; for ( ConstraintDescriptor descriptor : constraintDescriptors ) { if ( groups != null && Collections.disjoint( descriptor.getGroups(), groups ) ) { @@ -190,6 +192,8 @@ private static boolean applyConstraints(Set> constraintD applyMax( property, descriptor ); // apply hibernate validator specific constraints - we cannot import any HV specific classes though! + // no need to check explicitly for @Range. @Range is a composed constraint using @Min and @Max which + // will be taken care later applyLength( property, descriptor, propertyDesc ); // pass an empty set as composing constraints inherit the main constraint and thus are matching already @@ -226,7 +230,10 @@ private static void applyMax(Property property, ConstraintDescriptor descript } private static void applySQLCheck(Column col, String checkConstraint) { - if ( StringHelper.isNotEmpty( col.getCheckConstraint() ) ) { + String existingCheck = col.getCheckConstraint(); + // need to check whether the new check is already part of the existing check, because applyDDL can be called + // multiple times + if ( StringHelper.isNotEmpty( existingCheck ) && !existingCheck.contains( checkConstraint ) ) { checkConstraint = col.getCheckConstraint() + " AND " + checkConstraint; } col.setCheckConstraint( checkConstraint );