From: zaid s. k. (JIRA) <no...@at...> - 2006-05-31 12:19:21
|
wrong generation of class alias ------------------------------- Key: HB-1558 URL: http://opensource.atlassian.com/projects/hibernate/browse/HB-1558 Project: Hibernate2 Type: Bug Components: core Versions: 2.1.1 Environment: hibernate, oracle10g Reporter: zaid saeedi khan Hi, I have a table USERROLE as follows: USERID ROLEID 1 1 1 2 2 2 2 3 2 1 I want the following SQL query select ur1.USERID, (select count(ur2.roleid) from userrole ur2 where ur1.userid=ur2.userid) from userrole ur1 group by userid output is: 1 2 2 3 i.e. I simply want to show the number of roles against each user. Now when I use hibernate, I make use of derived property and specify the subselect in the formula attribute. I have GroupBy.hgm.xml mapped to USERROLE and GroupBy.java as model which consists of id and count. I use Session session = sessionFactory.openSession(); String query = "from GroupBy gb group by gb.userId"; List results = session.find(query); BUT THE PROBLEM IS HIBERNATE DOES NOT ACCEPT gb AS THE TABLE ALIAS RATHER AS SHOWN BELOW IT GENERATES groupby0_ AS THE ALIAS. Hibernate: select groupby0_.USERID as USERID, (select count(*) from USERROLE ur1 where ur1.userId=groupby0_.userId) as f0_ from USERROLE groupby0_ group by groupby0_.USERID SO TO PERFORM MY QUERY I HAD TO HARDCODE(VERY BAD) groupby0_ IN THE FORMULA ATTRIBUTE AS FOLLOWS: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.a.test.model.GroupBy" table="USERROLE"> <id name="userId" column="USERID"> <generator class="increment"/> </id> <property name="count" formula="(select count(*) from USERROLE ur1 where ur1.userId=groupby0_.userId)" /> </class> </hibernate-mapping> Please help me to workaround this problem. Thanks in advance. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |