HHH-14810 @NotBlank and @NotEmpty were used, "NOT NULL" option wasn't add in generated DDL.
- add @NotEmpty, @NotBlank annotation on applyNotNull method in TypeSafeActivator - add test case for checking NotNull DDL rule - remote deprecated annotation on DDLTest
This commit is contained in:
parent
d78140d521
commit
5f2342bc9e
|
@ -15,6 +15,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.boot.internal.ClassLoaderAccessImpl;
|
||||
|
@ -43,11 +44,6 @@ import org.jboss.logging.Logger;
|
|||
|
||||
import jakarta.validation.Validation;
|
||||
import jakarta.validation.ValidatorFactory;
|
||||
import jakarta.validation.constraints.Digits;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import jakarta.validation.metadata.BeanDescriptor;
|
||||
import jakarta.validation.metadata.ConstraintDescriptor;
|
||||
import jakarta.validation.metadata.PropertyDescriptor;
|
||||
|
@ -321,7 +317,10 @@ class TypeSafeActivator {
|
|||
|
||||
private static boolean applyNotNull(Property property, ConstraintDescriptor<?> descriptor) {
|
||||
boolean hasNotNull = false;
|
||||
if ( NotNull.class.equals( descriptor.getAnnotation().annotationType() ) ) {
|
||||
// NotNull, NotEmpty, and NotBlank annotation add not-null on column
|
||||
if ( NotNull.class.equals( descriptor.getAnnotation().annotationType())
|
||||
|| NotEmpty.class.equals( descriptor.getAnnotation().annotationType())
|
||||
|| NotBlank.class.equals( descriptor.getAnnotation().annotationType())) {
|
||||
// single table inheritance should not be forced to null due to shared state
|
||||
if ( !( property.getPersistentClass() instanceof SingleTableSubclass ) ) {
|
||||
//composite should not add not-null on all columns
|
||||
|
|
|
@ -9,12 +9,7 @@ package org.hibernate.orm.test.annotations.beanvalidation;
|
|||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Transient;
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Entity
|
||||
public class Address {
|
||||
|
@ -42,7 +37,7 @@ public class Address {
|
|||
this.country = country;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
public String getLine1() {
|
||||
return line1;
|
||||
}
|
||||
|
@ -51,6 +46,7 @@ public class Address {
|
|||
this.line1 = line1;
|
||||
}
|
||||
|
||||
@NotBlank
|
||||
public String getLine2() {
|
||||
return line2;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.hibernate.mapping.Column;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -37,6 +36,20 @@ public class DDLTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
assertFalse( zipColumn.isNullable() );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNotNullDDL() {
|
||||
PersistentClass classMapping = metadata().getEntityBinding( Address.class.getName() );
|
||||
Column stateColumn = classMapping.getProperty( "state" ).getColumns().get(0);
|
||||
assertFalse("Validator annotations are applied on state as it is @NotNull", stateColumn.isNullable());
|
||||
|
||||
Column line1Column = classMapping.getProperty( "line1" ).getColumns().get(0);
|
||||
assertFalse("Validator annotations are applied on line1 as it is @NotEmpty", line1Column.isNullable());
|
||||
|
||||
Column line2Column = classMapping.getProperty( "line2" ).getColumns().get(0);
|
||||
assertFalse("Validator annotations are applied on line2 as it is @NotBlank", line2Column.isNullable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyOnIdColumn() {
|
||||
PersistentClass classMapping = metadata().getEntityBinding( Tv.class.getName() );
|
||||
|
@ -45,7 +58,6 @@ public class DDLTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-5281" )
|
||||
public void testLengthConstraint() {
|
||||
PersistentClass classMapping = metadata().getEntityBinding( Tv.class.getName() );
|
||||
Column modelColumn = classMapping.getProperty( "model" ).getColumns().get(0);
|
||||
|
|
Loading…
Reference in New Issue