HHH-10242 Detect ambiguous properties
boolean idId() + UUID getId() is ambiguous if no @Transient is involved
(cherry picked from commit 5cc5ed1c84
)
This commit is contained in:
parent
3d89f9e771
commit
32806083ef
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue