• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AliasToBeanTransformer

 
deepa karra
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have two tables User and Department. I want to retreive two columns username from User and department name from Department using Hibernate.

I created a class User_Department as follows:

public class User_Department{
private String USERNAME;
private String DeptName;

...Getters and setters

}



The Query I am using to retreive the columns is

queryString = "select a.USERNAME as USERNAME,b.DeptName as DeptName from User as a,Department as b where a.deptno=b.deptno and a.USERNAME like ? ";
result = (List) session.createQuery(queryString).setResultTransformer(new AliasToBeanResultTransformer(User_Department.class).setString(0,userName).list();


I executed the program 4 times with the same parameter and 4 rows with the same data are displayed instead of displaying it once.
When I deleted all the data from both user and department tables, the above query still displays the output from User_Department class.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic