为什么总是报错?
on in thread "main" org.hibernate.QueryException: could not resolve property: menuID of: com.tts.hibernate.Menu [select mu.actionValue0 from com.tts.hibernate.Menuusers as mu where mu.menu.menuID=? and mu.user.userID=?]我有三张表
user(userid 主键, username);  
menu(menuid 主键, menuname); 
menuusers(menuusersid 主键,menuid 外键, userid 外键)
menuusers.java如下:public class Menuusers implements java.io.Serializable { // Fields private Integer menuUserId;
private User user;
private Menu menu;
private short actionValue0;
private short actionValue1;
private short actionValue2;
private short actionValue3;
private short actionValue4; // Constructors /** default constructor */
public Menuusers() {
} /** minimal constructor */
public Menuusers(Menu menu, short actionValue0, short actionValue1,
short actionValue2, short actionValue3, short actionValue4) {
this.menu = menu;
this.actionValue0 = actionValue0;
this.actionValue1 = actionValue1;
this.actionValue2 = actionValue2;
this.actionValue3 = actionValue3;
this.actionValue4 = actionValue4;
}.....
menuusers的映射关系如下:
<hibernate-mapping>
    <class name="com.tts.hibernate.Menuusers" table="menuusers" catalog="bts">
        <id name="menuUserId" type="integer">
            <column name="menuUserID" />
            <generator class="identity" />
        </id>
        <many-to-one name="user" class="com.tts.hibernate.User" fetch="select">
            <column name="userID" />
        </many-to-one>
        <many-to-one name="menu" class="com.tts.hibernate.Menu" fetch="select">
            <column name="menuID" not-null="true" />
        </many-to-one>
        <property name="actionValue0" type="short">
            <column name="actionValue0" not-null="true" />
        </property>
        <property name="actionValue1" type="short">
            <column name="actionValue1" not-null="true" />
        </property>
        <property name="actionValue2" type="short">
            <column name="actionValue2" not-null="true" />
        </property>
        <property name="actionValue3" type="short">
            <column name="actionValue3" not-null="true" />
        </property>
        <property name="actionValue4" type="short">
            <column name="actionValue4" not-null="true" />
        </property>
    </class>
</hibernate-mapping>我想通过menuid和userid一起查询,因为初学,所以参照例子在MenuusersDAO里自己写了一个方法: public List findByMidUid (java.lang.Integer menuId, java.lang.Integer userId){
log.debug("getting Menuusers instance with menuid: " + menuId +"userid"+ userId );
try {
String hql = "from Menuusers as mu where mu.menu.menuID=? and mu.user.userID=?";
Query queryObject = getSession().createQuery(hql);
queryObject.setParameter(0, menuId);
queryObject.setParameter(1,userId);
return queryObject.list();
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}但是为什么总是报错呢?我的毕业设计哦,时间好紧张的说~大侠们帮帮忙吧!!!!
为什么总是报错?
on in thread "main" org.hibernate.QueryException: could not resolve property: menuID of: com.tts.hibernate.Menu [select mu.actionValue0 from com.tts.hibernate.Menuusers as mu where mu.menu.menuID=? and mu.user.userID=?]

解决方案 »

  1.   

    同病相怜我也做毕设,Hibernate问题相当多!
      

  2.   

    LZ看一下http://www.verycd.com/topics/249195/里面的“传智播客hibernate教程_多对多关联关系的映射与原理分析”
      

  3.   

    因为你设计到级联所以问题有点多,QueryException 查询异常,hibernate不能执行这个查询,设计到级联要考虑一个属性lazy="false"级联就是问题多 <many-to-one name="user" class="com.tts.hibernate.User" fetch="select" lazy="false"> 在这种地方添加不过具体的得看你设计的了,是多对多关系还是一对一关系你得搞清。自己再看看吧!
      

  4.   

    "from Menuusers as mu where mu.menu.menuID=? and mu.user.userID=?"; 
    这个查询语句写的有问题mu.menu.menuID这样不行,你可以用连接,虽然我数据库也学的不好,哈哈,我做毕业设计的时候hibernate查询遇到的问题也很多~~
      

  5.   

    用myeclips 里jutil 单元测试,设个断点一步一步的测试,不就知道问题出在哪里吗?
      

  6.   

    是要查找吧?试试这样的:public List findByMidUid (String menuId,String userId){ 
    String hql = "from Menuusers as mu where mu.menu.menuID='"+menuId+"' and mu.user.userID='"+userId+"'"; 
    List list=null;
    Transaction tx=null;
    Session session= HibernateUtil.createSession();
    tx=session.beginTransaction();
    list=session.createQuery(hql).list();
    Iterator it=list.iterator();
    while(it.hasNext()){
    Menuusers temp=Menuusers it.next();
     }
    tx.conmit();

    return list;//得到Menuusers 里所查的值,可以在JSP取结果:<td> <s:property value="menuusers.menu.menuName"/> </td>
    }
      

  7.   

    需要在前面方法中将menuId 、 userId转换成String类型