[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-4591) Criteria.createAlias not working for key-many-to-one associations of a composite-id
Sorin Postelnicu (JIRA)
noreply at atlassian.com
Thu Jun 23 12:40:54 EDT 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4591?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sorin Postelnicu updated HHH-4591:
----------------------------------
Attachment: aliascompositekey.zip
Here is a test package. Just copy this folder inside the "eg" hibernate tutorial sample, in the folder tutorials/eg/src/main/java/org/hibernate, and you can run the class called Main to test the problem with the createAlias for composite-key and key-many-to-one.
> 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.2.6, 3.2.7, 3.3.2, 3.5.5
> Environment: Hibernate 3.2.6.ga, 3.2.7.ga, 3.3.2.ga
> Database: Oragle10g
> Reporter: Luka
> Attachments: aliascompositekey.zip
>
>
> 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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list