日期:2014-05-20  浏览次数:20871 次

hibernate 映射问题(查询HQL语句)。
刚学hibenate,大家帮帮忙。。。谢谢!
我的三张表结构很简单,
 用户表systemuser(sysUid/pk,sysUname)
 菜单表systemmenu(sysMcode/pk,sysMname)
 用户菜单表systemusermenu(sysid/pk,sysUid/fk,sysMcode/fk)
POJO:
1.Systemuser.java
 private Integer sysUid;
 private String sysUname;
 private Set systemusermenus = new HashSet(0);
 ……
2.Systemmenu.java
 private Integer sysMcode;
 private String sysMname;
 private Set systemusermenus = new HashSet(0);
 ……
3.Systemusermenu.java
 private Integer sysid;
 private Systemmenu systemmenu;
 private Systemuser systemuser;
 ……
映射文件:
1.Systemuser.hbm.xml:
<set name="systemusermenus" inverse="true" cascade="all" lazy="false">
<key>
<column name="sysUid" />
</key>
<one-to-many class="com.xxm.hibernate.Systemusermenu" />
</set>
2.Systemmenu.hbm.xml:
<set name="systemusermenus" inverse="true" cascade="all" lazy="false">
<key>
<column name="sysMcode" />
</key>
<one-to-many class="com.xxm.hibernate.Systemusermenu" />
</set>
3.Systemusermenu.hbm.xml
<hibernate-mapping>
<class name="com.xxm.hibernate.Systemusermenu" table="systemusermenu" >
<id name="sysid" type="java.lang.Integer">
<column name="sysid" />
<generator class="native" />
</id>
<many-to-one name="systemmenu" class="com.xxm.hibernate.Systemmenu" fetch="select" cascade="none" outer-join="auto">
<column name="sysMcode" />
</many-to-one>
<many-to-one name="systemuser" class="com.xxm.hibernate.Systemuser" fetch="select" cascade="none" outer-join="auto">
<column name="sysUid" />
</many-to-one>
</class>
</hibernate-mapping>
问题:我想通过用户名来取得该用户所拥有的所有菜单。
HQL语句是否是这样写的:我现在就是报HQL语句错啊。。。
select u.sysUname,m.sysMcode,m.sysMname from Systemuser as u,Systemmenu as m,Systemusermenu as um 
where um.systemuser.sysUid = u.sysUid and um.systemmenu.sysMcode = m.sysMcode and u.sysUname:=sysUname
Query q = session.createQuery(hql);
q.setString("sysUname",sysUname);


------解决方案--------------------
报什么错?
------解决方案--------------------
把from Systemuser as u,Systemmenu as m,Systemusermenu as um 中的as拿掉,以前死在这上面过