@@ -311,7 +311,7 @@ private static boolean applyConstraints(
311
311
312
312
// Apply Hibernate Validator specific constraints - we cannot import any HV specific classes though!
313
313
// No need to check explicitly for @Range. @Range is a composed constraint using @Min and @Max which
314
- // will be taken care later.
314
+ // will be taken care of later.
315
315
applyLength ( property , descriptor , propertyDesc );
316
316
317
317
// Composing constraints
@@ -360,7 +360,7 @@ private static boolean isConstraintCompositionOfTypeOr(
360
360
return false ;
361
361
}
362
362
363
- final Class <? extends Annotation > composedAnnotation = descriptor .getAnnotation ().annotationType ();
363
+ final var composedAnnotation = descriptor .getAnnotation ().annotationType ();
364
364
return constraintCompositionTypeCache .computeIfAbsent ( composedAnnotation , value -> {
365
365
for ( Annotation annotation : value .getAnnotations () ) {
366
366
if ( "org.hibernate.validator.constraints.ConstraintComposition"
@@ -383,7 +383,7 @@ private static boolean isConstraintCompositionOfTypeOr(
383
383
private static void applyMin (Property property , ConstraintDescriptor <?> descriptor , Dialect dialect ) {
384
384
if ( Min .class .equals ( descriptor .getAnnotation ().annotationType () ) ) {
385
385
@ SuppressWarnings ("unchecked" )
386
- final ConstraintDescriptor < Min > minConstraint = (ConstraintDescriptor <Min >) descriptor ;
386
+ final var minConstraint = (ConstraintDescriptor <Min >) descriptor ;
387
387
final long min = minConstraint .getAnnotation ().value ();
388
388
for ( Selectable selectable : property .getSelectables () ) {
389
389
if ( selectable instanceof Column column ) {
@@ -396,7 +396,7 @@ private static void applyMin(Property property, ConstraintDescriptor<?> descript
396
396
private static void applyMax (Property property , ConstraintDescriptor <?> descriptor , Dialect dialect ) {
397
397
if ( Max .class .equals ( descriptor .getAnnotation ().annotationType () ) ) {
398
398
@ SuppressWarnings ("unchecked" )
399
- final ConstraintDescriptor < Max > maxConstraint = (ConstraintDescriptor <Max >) descriptor ;
399
+ final var maxConstraint = (ConstraintDescriptor <Max >) descriptor ;
400
400
final long max = maxConstraint .getAnnotation ().value ();
401
401
for ( Selectable selectable : property .getSelectables () ) {
402
402
if ( selectable instanceof Column column ) {
@@ -420,15 +420,16 @@ private static void applySQLCheck(Column column, String checkConstraint) {
420
420
private static boolean isNotNullDescriptor (ConstraintDescriptor <?> descriptor ) {
421
421
final Class <? extends Annotation > annotationType = descriptor .getAnnotation ().annotationType ();
422
422
return NotNull .class .equals (annotationType )
423
- || NotEmpty .class .equals (annotationType )
424
- || NotBlank .class .equals (annotationType );
423
+ || NotEmpty .class .equals (annotationType )
424
+ || NotBlank .class .equals (annotationType );
425
425
}
426
426
427
427
private static void markNotNull (Property property ) {
428
428
// single table inheritance should not be forced to null due to shared state
429
429
if ( !( property .getPersistentClass () instanceof SingleTableSubclass ) ) {
430
430
// composite should not add not-null on all columns
431
431
if ( !property .isComposite () ) {
432
+ property .setOptional ( false );
432
433
for ( Selectable selectable : property .getSelectables () ) {
433
434
if ( selectable instanceof Column column ) {
434
435
column .setNullable ( false );
@@ -449,7 +450,7 @@ private static void markNotNull(Property property) {
449
450
private static void applyDigits (Property property , ConstraintDescriptor <?> descriptor ) {
450
451
if ( Digits .class .equals ( descriptor .getAnnotation ().annotationType () ) ) {
451
452
@ SuppressWarnings ("unchecked" )
452
- final ConstraintDescriptor < Digits > digitsConstraint = (ConstraintDescriptor <Digits >) descriptor ;
453
+ final var digitsConstraint = (ConstraintDescriptor <Digits >) descriptor ;
453
454
final int integerDigits = digitsConstraint .getAnnotation ().integer ();
454
455
final int fractionalDigits = digitsConstraint .getAnnotation ().fraction ();
455
456
for ( Selectable selectable : property .getSelectables () ) {
@@ -466,7 +467,7 @@ private static void applySize(Property property, ConstraintDescriptor<?> descrip
466
467
if ( Size .class .equals ( descriptor .getAnnotation ().annotationType () )
467
468
&& String .class .equals ( propertyDescriptor .getElementClass () ) ) {
468
469
@ SuppressWarnings ("unchecked" )
469
- final ConstraintDescriptor < Size > sizeConstraint = (ConstraintDescriptor <Size >) descriptor ;
470
+ final var sizeConstraint = (ConstraintDescriptor <Size >) descriptor ;
470
471
final int max = sizeConstraint .getAnnotation ().max ();
471
472
for ( Column col : property .getColumns () ) {
472
473
if ( max < Integer .MAX_VALUE ) {
@@ -520,19 +521,19 @@ private static Property findPropertyByName(PersistentClass associatedClass, Stri
520
521
property = associatedClass .getProperty ( element );
521
522
}
522
523
else {
523
- if ( ! property .isComposite () ) {
524
- return null ;
524
+ if ( property .isComposite () ) {
525
+ property = ( ( Component ) property . getValue () ). getProperty ( element ) ;
525
526
}
526
527
else {
527
- property = ( ( Component ) property . getValue () ). getProperty ( element ) ;
528
+ return null ;
528
529
}
529
530
}
530
531
}
531
532
}
532
533
}
533
534
catch ( MappingException e ) {
534
535
try {
535
- //if we do not find it try to check the identifier mapper
536
+ //if we do not find it, try to check the identifier mapper
536
537
if ( associatedClass .getIdentifierMapper () == null ) {
537
538
return null ;
538
539
}
@@ -544,11 +545,11 @@ private static Property findPropertyByName(PersistentClass associatedClass, Stri
544
545
property = associatedClass .getIdentifierMapper ().getProperty ( element );
545
546
}
546
547
else {
547
- if ( ! property .isComposite () ) {
548
- return null ;
548
+ if ( property .isComposite () ) {
549
+ property = ( ( Component ) property . getValue () ). getProperty ( element ) ;
549
550
}
550
551
else {
551
- property = ( ( Component ) property . getValue () ). getProperty ( element ) ;
552
+ return null ;
552
553
}
553
554
}
554
555
}
@@ -562,8 +563,9 @@ private static Property findPropertyByName(PersistentClass associatedClass, Stri
562
563
}
563
564
564
565
private static ValidatorFactory getValidatorFactory (ActivationContext context ) {
565
- // IMPL NOTE : We can either be provided a ValidatorFactory or make one. We can be provided
566
- // a ValidatorFactory in 2 different ways. So here we "get" a ValidatorFactory in the following order:
566
+ // IMPL NOTE: We can either be provided a ValidatorFactory or make one. We can be provided
567
+ // a ValidatorFactory in 2 different ways. So here we "get" a ValidatorFactory
568
+ // in the following order:
567
569
// 1) Look into SessionFactoryOptions.getValidatorFactoryReference()
568
570
// 2) Look into ConfigurationService
569
571
// 3) build a new ValidatorFactory
0 commit comments