[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5786) TypeSafeActivator.applyDDL doesn't process comprising constraints when @NotNull goes first
Enrico Pizzorno (JIRA)
noreply at atlassian.com
Fri Dec 10 08:59:13 EST 2010
TypeSafeActivator.applyDDL doesn't process comprising constraints when @NotNull goes first
------------------------------------------------------------------------------------------
Key: HHH-5786
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5786
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.0
Reporter: Enrico Pizzorno
Priority: Minor
We have a custom constraint defined as:
{quote}
@Size(max=60)
...
public @interface Name {
String message() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
{quote}
Then we can annotate some entities like this:
{quote}
public class MyEntity {
...
@NotNull
@Name
private String name;
...
}
{quote}
If @NotNull goes before @Name then when contraints are applied to column definitions by calling TypeSafeActivator.applyDDL the constraint @Size(max=60) is ignored.
I think the problem is at line 200 from *org.hibernate.cfg.beanvalidation.TypeSafeActivator*, method *private static boolean applyConstraints(Set<ConstraintDescriptor<?>> constraintDescriptors, Property property, PropertyDescriptor propertyDesc, Set<Class<?>> groups, boolean canApplyNotNull)*:
{quote}
// pass an empty set as composing constraints inherit the main constraint and thus are matching already
hasNotNull = hasNotNull || applyConstraints(
descriptor.getComposingConstraints(),
property, propertyDesc, null,
canApplyNotNull );
{quote}
If @NotNull is processed first then hasNotNull is set to true so the call to applyConstraints at line 200 is never made.
Changing the order of the "or" operands will solve the problem:
{quote}
// pass an empty set as composing constraints inherit the main constraint and thus are matching already
hasNotNull = applyConstraints(
descriptor.getComposingConstraints(),
property, propertyDesc, null,
canApplyNotNull ) || hasNotNull;
{quote}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list