HHH-10242 Detect ambiguous properties
boolean idId() + UUID getId() is ambiguous if no @Transient is involved
This commit is contained in:
parent
2e6811f413
commit
5cc5ed1c84
|
@ -79,6 +79,7 @@ class PropertyContainer {
|
||||||
propertyAccessMap = initProperties( AccessType.PROPERTY );
|
propertyAccessMap = initProperties( AccessType.PROPERTY );
|
||||||
|
|
||||||
considerExplicitFieldAndPropertyAccess();
|
considerExplicitFieldAndPropertyAccess();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public XClass getEntityAtStake() {
|
public XClass getEntityAtStake() {
|
||||||
|
@ -184,6 +185,12 @@ class PropertyContainer {
|
||||||
if ( mustBeSkipped( property ) ) {
|
if ( mustBeSkipped( property ) ) {
|
||||||
continue;
|
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 );
|
propertiesMap.put( property.getName(), property );
|
||||||
}
|
}
|
||||||
return propertiesMap;
|
return propertiesMap;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import javax.transaction.SystemException;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
|
import org.hibernate.annotations.common.reflection.XClass;
|
||||||
import org.hibernate.cache.CacheException;
|
import org.hibernate.cache.CacheException;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
|
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
|
||||||
|
@ -1751,4 +1752,7 @@ public interface CoreMessageLogger extends BasicLogger {
|
||||||
@LogMessage(level = INFO)
|
@LogMessage(level = INFO)
|
||||||
@Message(value = "Omitting cached file [%s] as the mapping file is newer", id = 473)
|
@Message(value = "Omitting cached file [%s] as the mapping file is newer", id = 473)
|
||||||
void cachedFileObsolete(File cachedFile);
|
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