mapping order impacting behavior leading to bug

Description

Following mapping fails:

<hibernate-mapping default-access="property" package="case419703">

<class abstract="false" dynamic-insert="true" dynamic-update="true" name="TestB"
table="TEST_B">
<composite-id class="case419703.key.FrameworkKeyCustID"
name="frameworkKey">
<key-property column="NR_RZBK" name="frameworkCustId"/>
<key-property column="TXT_OID" name="frameworkOid"/>
</composite-id>
<version column="NR_VERSION" name="frameworkVersion"/>

<set cascade="persist, merge, save-update" inverse="true" lazy="true" name="testC">
<key>
<column name="NR_RZBK"/>
<column name="TXT_OID_TESTB"/>
</key>
<one-to-many class="TestC"/>
</set>
</class>

<class abstract="true" dynamic-insert="true" dynamic-update="true" name="AbstractTestC"
table="notable">
<composite-id class="case419703.key.FrameworkKeyCustID"
name="frameworkKey">
<key-property column="NR_RZBK" name="frameworkCustId"/>
<key-property column="TXT_OID" name="frameworkOid"/>
</composite-id>
<version column="NR_VERSION" name="frameworkVersion"/>

<union-subclass dynamic-insert="true" dynamic-update="true" name="case419703.TestC"
table="TEST_C">
<property column="PID" name="pid" update="false"/>
<property column="TXT_OID_TESTB" name="fkReverseTestB"/>
<many-to-one cascade="persist, merge, save-update" class="case419703.TestB"
fetch="select" insert="false" lazy="no-proxy" name="reverseTestB"
update="false" >
<column name="NR_RZBK" />
<column name="TXT_OID_TESTB" />
<!-- formula>'TXT_OID_TESTB'</formula-->
</many-to-one>
</union-subclass>
</class>
</hibernate-mapping>

however changing to

<many-to-one cascade="persist, merge, save-update" class="case419703.TestB"
fetch="select" insert="false" lazy="no-proxy" name="reverseTestB"
update="false" >
<column name="NR_RZBK" />
<column name="TXT_OID_TESTB" />
<!-- formula>'TXT_OID_TESTB'</formula-->
</many-to-one>
<property column="PID" name="pid" update="false"/>
<property column="TXT_OID_TESTB" name="fkReverseTestB"/>
works.

Something is wrong with th algo.
See attached testcase.

Environment

None

Activity

Show:
Strong Liu
February 22, 2010, 8:04 PM

the SELECT issued in this case is

and then in org.hibernate.collection.PersistentSet, hibernate will try to construct TestC object:

But the aliases returned by descriptor.getSuffixedElementAliases() is from
org.hibernate.persister.collection.AbstractCollectionPersister.AbstractCollectionPersister(Collection, CollectionRegionAccessStrategy, Configuration, SessionFactoryImplementor)

in this case, according to the algorithm of Column.getAlias(Dialect), the key column TXT_OID's alias is TXT2_1_, which is same as the column TXT_OID_TESTB's.

this explains why changing the order of property in hbm works. After the change, the alias will be different.

Strong Liu
February 22, 2010, 10:50 PM

two ways of fixing this I guess:
1.
open the comment below:
http://anonsvn.jboss.org/repos/hibernate/core/trunk/core/src/main/java/org/hibernate/util/StringHelper.java

2. use Column.getAlias(Dialect,Table) instead of Column.getAlias(Dialect) in org.hibernate.persister.collection.AbstractCollectionPersister.AbstractCollectionPersister(Collection, CollectionRegionAccessStrategy, Configuration, SessionFactoryImplementor)

Strong Liu
February 23, 2010, 11:52 PM

patch applied, I picked option 2 in my previously comment in that patch.

Strong Liu
February 24, 2010, 12:03 AM

require release notes

Steve Ebersole
March 21, 2011, 7:09 PM

Bulk closing stale resolved issues

Fixed

Assignee

Strong Liu

Reporter

Anthony Patricio

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure