-->
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: Alias to Entity mapping problem
PostPosted: Fri Nov 05, 2004 7:25 pm 
Newbie

Joined: Fri Nov 05, 2004 7:14 pm
Posts: 1
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() : ""));
}

_________________
Bernd VanSkiver


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 4:23 pm 
Newbie

Joined: Mon Nov 08, 2004 4:20 pm
Posts: 1
I was having the same problem. Does anyone know how to get it to work?


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.