ManyToOneType.isDirty

Description

public boolean isDirty(
Object old,
Object current,
SessionImplementor session) throws HibernateException {
if ( isSame( old, current ) )
{ return false; }
Object oldid = getIdentifier( old, session );
Object newid = getIdentifier( current, session );
return getIdentifierType( session ).isDirty( oldid, newid, session );
}
return getIdentifierType( session ).isDirty( oldid, newid, session );
==>
return getIdentifierOrUniqueKeyType( session ).isDirty( oldid, newid, session );

for property-ref in xml
getIdentifierType( session ) return identity type of the associated entity
instead of what the property-ref property type is expected

ADD:
Object oldid = getIdentifier( old, session );
Object newid = getIdentifier( current, session );
getIdentifier() process the property-ref perfectly

previous issue:
https://hibernate.atlassian.net/browse/HHH-9335

hbm.xml:
Person
<class entity-name="O2O_Person" table="ONE_TO_ONE_PERSON">
<id name="id" type="java.math.BigDecimal">
<column name="ID" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<many-to-one name="address" entity-name="O2O_Address" property-ref="fk" cascade="save-update" unique="true">
<column name="ADDRESS_ID" ></column>
</many-to-one>
</class>
Address
<class entity-name="O2O_Address" table="ONE_TO_ONE_ADDRESS">
<id name="id" type="java.math.BigDecimal">
<column name="ID" />
</id>
<property name="addressName" type="java.lang.String">
<column name="NAME" />
</property>
</class>

exception:
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.math.BigDecimal
at org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor.areEqual(BigDecimalTypeDescriptor.java:36)
at org.hibernate.type.AbstractStandardBasicType.isEqual(AbstractStandardBasicType.java:207)
at org.hibernate.type.AbstractStandardBasicType.isSame(AbstractStandardBasicType.java:197)
at org.hibernate.type.AbstractStandardBasicType.isDirty(AbstractStandardBasicType.java:233)
at org.hibernate.type.AbstractStandardBasicType.isDirty(AbstractStandardBasicType.java:225)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:312)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:321)
at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:294)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:4237)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:546)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:232)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:159)

Very Important:
this exception occurred only when the identifier type of the associated entity is BigDecimal(and other type which's TypeDescriptor override the "areEquals" method of AbstractTypeDescriptor)

Environment

h 4.3.5
oracle 11gr2

Status

Assignee

Unassigned

Reporter

xinhuil

Fix versions

None

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure