Criteria.createAlias not working for key-many-to-one associations of a composite-id
-----------------------------------------------------------------------------------
Key: HHH-4591
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4591
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.3.2, 3.2.7, 3.2.6
Environment: Hibernate 3.2.6.ga, 3.2.7.ga, 3.3.2.ga
Database: Oragle10g
Reporter: Luka
I'm trying to create an alias to apply a filter on a composite primary-key
association, but I'm getting an invalid SQL generated by the ctiteria api: in the SQL
there is the filter applied in the where, but the join for the alias is missing in the
from.
Here is a sample of the problem:
Mappings (I stripped non relevant info):
TableOne.hbm.xml
<hibernate-mapping default-cascade="none">
<class name="TableOne" table="TABLE_ONE"
dynamic-insert="false" dynamic-update="false">
<id name="idTableOne" type="java.lang.Long"
unsaved-value="null">
<column name="ID_CONTRATTO"/>
<generator class="sequence">
<param name="sequence">S_TABLE_ONE</param>
</generator>
</id>
<set name="tableOneToTableTwo" order-by="ID_TABLE_ONE"
lazy="true" fetch="select" inverse="true"
cascade="none">
<key>
<column name="ID_TABLE_ONE"/>
</key>
<one-to-many class="TableOneToTableTwo"/>
</set>
</class>
</hibernate-mapping>
TableOneToTableTwo.hbm.xml
<hibernate-mapping default-cascade="none">
<class name="TableOneToTableTwo" table="TABLE_ONE_TO_TABLE_TWO"
dynamic-insert="false" dynamic-update="false">
<composite-id name="tableOneToTableTwoPk"
class="TableOneToTableTwoPK">
<key-many-to-one name="tableOne" class="TableOne" >
<column name="ID_TABLE_ONE"/>
</key-many-to-one>
<key-many-to-one name="tabelTwo" class="TabelTwo" >
<column name="ID_TABLE_TWO"/>
</key-many-to-one>
</composite-id>
</class>
</hibernate-mapping>
TabelTwo.hbm.xml
<hibernate-mapping default-cascade="none">
<class name="TabelTwo" table="TABLE_TWO"
dynamic-insert="false" dynamic-update="false">
<id name="idTableTwo" type="java.lang.Long"
unsaved-value="null">
<column name="ID_TABLE_TWO"/>
<generator class="sequence">
<param name="sequence">S_TABLE_TWO</param>
</generator>
</id>
<property name="codTabelTwo" type="java.lang.String">
<column name="COD_TABLE_TWO" not-null="true"
unique="false"/>
</property>
</class>
</hibernate-mapping>
Code:
Criteria hibCrit = getSession().createCriteria(TableOne.class);
hibCrit.createAlias("tableOneToTableTwo", "tableOneToTableTwo");
hibCrit.createAlias("tableOneToTableTwo.tableOneToTableTwoPk.tabelTwo",
"tabelTwo");
hibCrit.add(Restrictions.eq("tabelTwo.codTabelTwo", "AAA"));
hibCrit.list();
Generated SQL using Oracle10G dialect (I stripped columns in select):
SELECT [...]
FROM TABLE_ONE this_
INNER JOIN TABLE_ONE_TO_TABLE_TWO tabelTwoco1_ ON this_.ID_TABLE_ONE =
tabelTwoco1_.ID_TABLE_ONE
WHERE tabelTwo2_.COD_TABLE_TWO = ?
The "tabelTwo2_" should be the sql alias for criteria alias
"tabelTwo", but the table and the join are missing in the from...
I also tried using createCriteria:
Criteria hibCrit = getSession().createCriteria(TableOne.class);
hibCrit.createAlias("tableOneToTableTwo", "tableOneToTableTwo");
Criteria tableTwoCrit =
hibCrit.createCriteria("tableOneToTableTwo.tableOneToTableTwoPk.tabelTwo",
"tabelTwo");
tableTwoCrit.add(Restrictions.eq("tabelTwo.codTabelTwo", "AAA"));
hibCrit.list();
But i get the same sql query.
Also upgrading Hibernate result in the same behavior.
--
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