From 5cc5ed1c84584939efe28dd3f8373f68ff194730 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Thu, 5 Nov 2015 09:54:43 +0100 Subject: [PATCH] HHH-10242 Detect ambiguous properties boolean idId() + UUID getId() is ambiguous if no @Transient is involved --- .../src/main/java/org/hibernate/cfg/PropertyContainer.java | 7 +++++++ .../java/org/hibernate/internal/CoreMessageLogger.java | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java index e2ef5b6b3f..e603ad38d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java @@ -79,6 +79,7 @@ class PropertyContainer { propertyAccessMap = initProperties( AccessType.PROPERTY ); considerExplicitFieldAndPropertyAccess(); + } public XClass getEntityAtStake() { @@ -184,6 +185,12 @@ class PropertyContainer { if ( mustBeSkipped( property ) ) { continue; } + // HHH-10242 detect registration of the same property twice eg boolean isId() + UUID getId() + XProperty oldProperty = propertiesMap.get( property.getName() ); + if ( oldProperty != null ) { + throw LOG.throwAmbiguousPropertyException( this.xClass, oldProperty.getName(), oldProperty.getType(), property.getType() ); + } + propertiesMap.put( property.getName(), property ); } return propertiesMap; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 01aab257df..c99295ee1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -23,6 +23,7 @@ import javax.transaction.SystemException; import org.hibernate.HibernateException; import org.hibernate.LockMode; +import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.cache.CacheException; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.dialect.spi.DialectResolver; @@ -1751,4 +1752,7 @@ public interface CoreMessageLogger extends BasicLogger { @LogMessage(level = INFO) @Message(value = "Omitting cached file [%s] as the mapping file is newer", id = 473) void cachedFileObsolete(File cachedFile); + + @Message(value = "Ambiguous property detected %s.%s (of types %s and %s). Mark one as @Transient.", id = 474) + HibernateException throwAmbiguousPropertyException(XClass entity, String propertyName, XClass firstPropertyType, XClass secondPropertyType); }