[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4825?page=c...
]
Strong Liu commented on HHH-4825:
---------------------------------
the SELECT issued in this case is
{code}
Hibernate:
select
testb0_.NR_RZBK as NR1_0_,
testb0_.TXT_OID as TXT2_0_,
testb0_.NR_VERSION as NR3_0_
from
TEST_B testb0_
Hibernate:
select
testc0_.NR_RZBK as NR1_1_,
testc0_.TXT_OID_TESTB as TXT2_1_,
testc0_.NR_RZBK as NR1_1_0_,
testc0_.TXT_OID as TXT2_1_0_,
testc0_.NR_VERSION as NR3_1_0_,
testc0_.PID as PID2_0_,
testc0_.TXT_OID_TESTB as TXT2_2_0_,
testc0_.NR_RZBK as NR1_2_0_
from
TEST_C testc0_
where
testc0_.NR_RZBK=?
and testc0_.TXT_OID_TESTB=?
{code}
and then in org.hibernate.collection.PersistentSet, hibernate will try to construct TestC
object:
{code}
public Object readFrom(
ResultSet rs,
CollectionPersister persister,
CollectionAliases descriptor,
Object owner) throws HibernateException, SQLException {
Object element = persister.readElement( rs, owner,
descriptor.getSuffixedElementAliases(), getSession() );
if (element!=null) tempList.add(element);
return element;
}
{code}
But the aliases returned by descriptor.getSuffixedElementAliases() is from
org.hibernate.persister.collection.AbstractCollectionPersister.AbstractCollectionPersister(Collection,
CollectionRegionAccessStrategy, Configuration, SessionFactoryImplementor)
{code}
...
keyColumnNames = new String[keySpan];
keyColumnAliases = new String[keySpan];
int k = 0;
while ( iter.hasNext() ) {
// NativeSQL: collect key column and auto-aliases
Column col = ( (Column) iter.next() );
keyColumnNames[k] = col.getQuotedName(dialect);
keyColumnAliases[k] = col.getAlias(dialect,table);
k++;
}
{code}
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.
mapping order impacting behavior leading to bug
-----------------------------------------------
Key: HHH-4825
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4825
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2, 3.5.0-Beta-3
Reporter: Anthony Patricio
Assignee: Strong Liu
Attachments: case419703.zip
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.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira