@@ -422,10 +422,10 @@ else if ( !allowMutation ) {
422422 LOG .lazyPropertyFetchingAvailable ( name );
423423 }
424424
425- lazy = persistentClass .isLazy () && (
425+ lazy = persistentClass .isLazy ()
426426 // 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 ();
429429
430430 mutable = persistentClass .isMutable ();
431431 if ( persistentClass .isAbstract () == null ) {
@@ -451,18 +451,24 @@ && isAbstractClass( persistentClass.getMappedClass() ) ) {
451451
452452 polymorphic = persistentClass .isPolymorphic ();
453453 inherited = persistentClass .isInherited ();
454- superclass = inherited ?
455- persistentClass .getSuperclass ().getEntityName () :
456- null ;
454+ superclass = inherited
455+ ? persistentClass .getSuperclass ().getEntityName ()
456+ : null ;
457457 hasSubclasses = persistentClass .hasSubclasses ();
458458
459459 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+ }
466472 }
467473
468474 hasCollections = foundCollection ;
@@ -520,9 +526,8 @@ private void verifyNaturalIdProperty(Property property) {
520526 final Value value = property .getValue ();
521527 if ( value instanceof ManyToOne toOne ) {
522528 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)'"
526531 );
527532 }
528533 }
@@ -585,7 +590,7 @@ private void mapPropertyToIndex(Property property, int i) {
585590 */
586591 public boolean isNaturalIdentifierInsertGenerated () {
587592 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" );
589594 }
590595 for ( int i = 0 ; i < naturalIdPropertyNumbers .length ; i ++ ) {
591596 final Generator strategy = generators [ naturalIdPropertyNumbers [i ] ];
@@ -698,9 +703,9 @@ public NonIdentifierAttribute[] getProperties() {
698703 }
699704
700705 public int getPropertyIndex (String propertyName ) {
701- Integer index = getPropertyIndexOrNull (propertyName );
706+ final Integer index = getPropertyIndexOrNull ( propertyName );
702707 if ( index == null ) {
703- throw new HibernateException ("Unable to resolve property: " + propertyName );
708+ throw new HibernateException ( "Unable to resolve property: " + propertyName );
704709 }
705710 return index ;
706711 }
0 commit comments