Hibernate version: 3.1.rc2
Mapping documents:
Resurs (resource)
Code:
<class name="Resurs" table="RESURS">
<id name="id">
<column name="RESURSID" sql-type="INTEGER"/>
<generator class="identity">
</generator>
</id>
....
<set name="egnaresurser" lazy="true" inverse="true" cascade="save-update" where="TOMTSTAMP is null">
<key column="RESURSID1" on-delete="noaction" not-null="true"/>
<one-to-many class="ResursRelation"/>
</set>
</class>
ResursRelation (relationship between resources)
Code:
<hibernate-mapping package="matrix.v.dataaccess.pojo">
<class name="ResursRelation" table="RESURSRELATION">
<composite-id>
<key-many-to-one lazy="false" name="resurs1" class="Resurs" foreign-key="FK_RESREL_RES1">
<column name="RESURSID1" sql-type="INTEGER"/>
</key-many-to-one>
<key-many-to-one lazy="false" name="resurs2" class="Resurs" foreign-key="FK_RESREL_RES2">
<column name="RESURSID2" sql-type="INTEGER"/>
</key-many-to-one>
<key-many-to-one lazy="false" name="typ" class="ResursRelationtyp" foreign-key="FK_RESRELT_RESREL">
<column name="RESRELTYPID" sql-type="INTEGER"/>
</key-many-to-one>
<key-property name="frantstamp" column="FRANTSTAMP" type="timestamp"/>
</composite-id>
....
</class>
ProblemHave seen similar questions on the forum about traversing collection association with multiple inner joins that work fine with HSQL but give undefined table aliases with the Criteria API. The following HSQL works great against the mapping documents:
Code:
select version Version version join version.egnaresurser relation join relation.typ relationtyp join relation.resurs2 relationresurs where relationtyp.beteckning='instans' and relationresurs.beteckning='SAE'
whereas with the Criteria API:
Code:
Criteria versionCriteria = session.createCriteria(Version.class)
.createAlias("egnaresurser","egnaresurs");
Criteria egnaresursTyp = versionCriteria.createCriteria("egnaresurs.typ");
egnaresursTyp.add( Expression.eq("beteckning","instans") );
Criteria egnaresursResurs2 = versionCriteria.createCriteria("egnaresurs.resurs2");
egnaresursResurs2.add( Expression.eq("beteckning",kriteria.getSubdomänBeteckning()) );
generates the first inner join to the collection (egenresurser) fine but the subsequent inner joins to the ResursRelationtyp table or back to the Resurs table. However, the where condition has unmapped aliases (to the missing table joins) correctly defining the expression declarations.
Question
What to do? Would love to use Criteria API rather than building dynamic HSQL strings.