Hibernate version: 2.1.6
Name and version of the database you are using: MSSQL Server 2000 SP3 with jtds as the JDBC driver
I am trying to use Criteria to retrieve information from my database. My criteria query is below. Everything seems to work fine with what it is doing, the base element that is returned is what I expect. The problem comes up when I try to reference an object used in the criteria by its Alias and get the wrong one returned. From doing debugging on what is actually going in to the ResultTransformer it appears that the alias's are off by one on the objects. For example I am referencing a User object and get return a State object (User lives in a State). The User object that I am expecting does go in to the ResultTransformer but is not reference by the correct Alias. So when I try to pull out my User object I get a cast exception because it is actually a State object that is in the spot where I am expecting the User object to be.
Here is my criteria code:
Code:
criteria = session.createCriteria(Collabgroup.class)
.add(Expression.eq("dataset", ds))
.createCriteria("users", "u")
.add(Expression.eq("userId", userId));
List cg = criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list();
And here is the code I am using to get data out of the map returned:
Code:
for(Iterator i = cg.iterator(); i.hasNext();) {
Map map = (Map)i.next();
Collabgroup c = (Collabgroup)map.get("this");
UserAuth u = (UserAuth)map.get("u");
System.out.println(c.getTitle() + " " + (u != null ? u.getScreenName() : ""));
}