Hopefully this will make sense:
I have 3 tables, Person, AltId, and AltIdDescn.
Person has the following mapping to AltId:
Code:
<set name="IdSet" table="ALT_ID" lazy="false" >
<key column="PERSON_ID" />
<one-to-many class="AltId" />
</set>
The AltId has the following mapping to AltIdDescn:
Code:
<many-to-one name="AltIdDescn" class="AltIdDescn" lazy="false" insert="false" update="false" >
<column name="ALT_ID_CDE" />
</many-to-one>
It is also important to note that the AltIdDescn object has a property on it called AltIdDescn. This property is one of the items i'm looking for and is causing the problem.
Code:
<property
column="ALT_ID_DESCN"
length="50"
name="AltIdDescn"
not-null="true"
type="string"
/>
Now, when i try to do the following projection.. i get an exception:
Code:
Criteria crit = session.createCriteria(Person.class);
Criteria altIdCrit = crit.createAlias("IdSet", "IdSet");
Criteria altIdDescnCrit = crit.createAlias("IdSet.AltIdDescn", "AltIdDescn");
ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("Person.Id"))
.add(Projections.property("IdSet.AltIdCde"))
.add(Projections.property("IdSet.AltIdDescn.AltIdDescn"));
crit.setProjection(Projections.distinct(projList));
List persons = crit.list();
The result of calling list() generates the following exception:
Quote:
org.hibernate.QueryException: could not resolve property: AltIdDescn.AltIdDescn of: AltIdCde
If i change this line:
Code:
.add(Projections.property("IdSet.AltIdDescn.AltIdDescn"));
to this:
Code:
.add(Projections.property("IdSet.AltIdDescn"));
I don't get the exception, but i get back an AltIdDescn object in my result set. I don't want an object returned, i want a single property on the object, a specific field in the database table.
Am i running into a problem with Hibernate not being able to traverse more than two tables in an association hierarchy? It doesn't make any sense why it wouldn't be able to continuously traverse the association paths.
Any help would be appreciated guys and gals.
-B