@@ -422,10 +422,10 @@ else if ( !allowMutation ) {
422
422
LOG .lazyPropertyFetchingAvailable ( name );
423
423
}
424
424
425
- lazy = persistentClass .isLazy () && (
425
+ lazy = persistentClass .isLazy ()
426
426
// TODO: this disables laziness even in non-pojo entity modes:
427
- !persistentClass .hasPojoRepresentation () || !isFinalClass ( persistentClass .getProxyInterface () ) )
428
- || bytecodeEnhancementMetadata .isEnhancedForLazyLoading ();
427
+ && ( !persistentClass .hasPojoRepresentation () || !isFinalClass ( persistentClass .getProxyInterface () ) )
428
+ || bytecodeEnhancementMetadata .isEnhancedForLazyLoading ();
429
429
430
430
mutable = persistentClass .isMutable ();
431
431
if ( persistentClass .isAbstract () == null ) {
@@ -451,18 +451,24 @@ && isAbstractClass( persistentClass.getMappedClass() ) ) {
451
451
452
452
polymorphic = persistentClass .isPolymorphic ();
453
453
inherited = persistentClass .isInherited ();
454
- superclass = inherited ?
455
- persistentClass .getSuperclass ().getEntityName () :
456
- null ;
454
+ superclass = inherited
455
+ ? persistentClass .getSuperclass ().getEntityName ()
456
+ : null ;
457
457
hasSubclasses = persistentClass .hasSubclasses ();
458
458
459
459
optimisticLockStyle = persistentClass .getOptimisticLockStyle ();
460
- final boolean isAllOrDirty = optimisticLockStyle .isAllOrDirty ();
461
- if ( isAllOrDirty && !dynamicUpdate ) {
462
- throw new MappingException ( "optimistic-lock=all|dirty requires dynamic-update=\" true\" : " + name );
463
- }
464
- if ( versionPropertyIndex != NO_VERSION_INDX && isAllOrDirty ) {
465
- throw new MappingException ( "version and optimistic-lock=all|dirty are not a valid combination : " + name );
460
+ //TODO: move these checks into the Binders
461
+ if ( optimisticLockStyle .isAllOrDirty () ) {
462
+ if ( !dynamicUpdate ) {
463
+ throw new MappingException ( "Entity '" + name
464
+ + "' has 'OptimisticLockType." + optimisticLockStyle
465
+ + "' but is not annotated '@DynamicUpdate'" );
466
+ }
467
+ if ( versionPropertyIndex != NO_VERSION_INDX ) {
468
+ throw new MappingException ( "Entity '" + name
469
+ + "' has 'OptimisticLockType." + optimisticLockStyle
470
+ + "' but declares a '@Version' field" );
471
+ }
466
472
}
467
473
468
474
hasCollections = foundCollection ;
@@ -520,9 +526,8 @@ private void verifyNaturalIdProperty(Property property) {
520
526
final Value value = property .getValue ();
521
527
if ( value instanceof ManyToOne toOne ) {
522
528
if ( toOne .getNotFoundAction () == NotFoundAction .IGNORE ) {
523
- throw new MappingException (
524
- "Attribute marked as natural-id can not also be a not-found association - "
525
- + propertyName ( property )
529
+ throw new MappingException ( "Association '" + propertyName ( property )
530
+ + "' marked as '@NaturalId' is also annotated '@NotFound(IGNORE)'"
526
531
);
527
532
}
528
533
}
@@ -585,7 +590,7 @@ private void mapPropertyToIndex(Property property, int i) {
585
590
*/
586
591
public boolean isNaturalIdentifierInsertGenerated () {
587
592
if ( naturalIdPropertyNumbers .length == 0 ) {
588
- throw new IllegalStateException ( "entity does not have a natural id: " + name );
593
+ throw new IllegalStateException ( "Entity '" + name + "' does not have a natural id" );
589
594
}
590
595
for ( int i = 0 ; i < naturalIdPropertyNumbers .length ; i ++ ) {
591
596
final Generator strategy = generators [ naturalIdPropertyNumbers [i ] ];
@@ -698,9 +703,9 @@ public NonIdentifierAttribute[] getProperties() {
698
703
}
699
704
700
705
public int getPropertyIndex (String propertyName ) {
701
- Integer index = getPropertyIndexOrNull (propertyName );
706
+ final Integer index = getPropertyIndexOrNull ( propertyName );
702
707
if ( index == null ) {
703
- throw new HibernateException ("Unable to resolve property: " + propertyName );
708
+ throw new HibernateException ( "Unable to resolve property: " + propertyName );
704
709
}
705
710
return index ;
706
711
}
0 commit comments