HHH-10242 Detect ambiguous properties

boolean idId() + UUID getId() is ambiguous if no @Transient is involved
This commit is contained in:
Emmanuel Bernard 2015-11-05 09:54:43 +01:00 committed by Steve Ebersole
parent 2e6811f413
commit 5cc5ed1c84
2 changed files with 11 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}