Skip to content

Commit 3280608

Browse files
emmanuelbernardsebersole
authored andcommitted
HHH-10242 Detect ambiguous properties
boolean idId() + UUID getId() is ambiguous if no @transient is involved (cherry picked from commit 5cc5ed1)
1 parent 3d89f9e commit 3280608

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/PropertyContainer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class PropertyContainer {
7979
propertyAccessMap = initProperties( AccessType.PROPERTY );
8080

8181
considerExplicitFieldAndPropertyAccess();
82+
8283
}
8384

8485
public XClass getEntityAtStake() {
@@ -184,6 +185,12 @@ private TreeMap<String, XProperty> initProperties(AccessType access) {
184185
if ( mustBeSkipped( property ) ) {
185186
continue;
186187
}
188+
// HHH-10242 detect registration of the same property twice eg boolean isId() + UUID getId()
189+
XProperty oldProperty = propertiesMap.get( property.getName() );
190+
if ( oldProperty != null ) {
191+
throw LOG.throwAmbiguousPropertyException( this.xClass, oldProperty.getName(), oldProperty.getType(), property.getType() );
192+
}
193+
187194
propertiesMap.put( property.getName(), property );
188195
}
189196
return propertiesMap;

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.hibernate.HibernateException;
2525
import org.hibernate.LockMode;
26+
import org.hibernate.annotations.common.reflection.XClass;
2627
import org.hibernate.cache.CacheException;
2728
import org.hibernate.dialect.Dialect;
2829
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
@@ -1751,4 +1752,7 @@ void cannotResolveNonNullableTransientDependencies(
17511752
@LogMessage(level = INFO)
17521753
@Message(value = "Omitting cached file [%s] as the mapping file is newer", id = 473)
17531754
void cachedFileObsolete(File cachedFile);
1755+
1756+
@Message(value = "Ambiguous property detected %s.%s (of types %s and %s). Mark one as @Transient.", id = 474)
1757+
HibernateException throwAmbiguousPropertyException(XClass entity, String propertyName, XClass firstPropertyType, XClass secondPropertyType);
17541758
}

0 commit comments

Comments
 (0)