-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Issue with projection across multiple tables
PostPosted: Wed Jun 06, 2007 9:20 am 
Beginner
Beginner

Joined: Tue Apr 24, 2007 12:53 pm
Posts: 28
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 3:06 pm 
Beginner
Beginner

Joined: Tue Apr 24, 2007 12:53 pm
Posts: 28
Well, i figured out the fix, but not necessarily what is wrong...


by changing the line:
Code:
.add(Projections.property("IdSet.AltIdDescn.AltIdDescn"));


to

Code:
.add(Projections.property("AltIdDescn.AltIdDescn"));


It works. If i reference the property starting at the alias name, Hibernate seems to know how to resolve the value.

I tried playing with it and not assigning an alias to the association path, and referencing the property from the root level. It didn't work. Anyone have any thoughts as to why this might be?

-B


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.