为什么总是报错?
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=?]
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=?]
解决方案 »
- sqljdbc4.jar到weblogic里面,使用时报空指针,具体问题内详
- 错误:org.apache.jasper.JasperException: java.lang.NullPointerException
- 关于往web项目添加jar包的一个问题!!
- 用InitialContext建立数据源,运行出现javax.naming.NoInitialContextException异常
- java中怎么实现发送email邮件
- 高分求救!JSP+MySql中文乱码问题
- WSDD部暑WebService时出错,请大侠帮助```
- Tomcat 请教
- 工作中运用SAX解析XML问题,急!!
- 奇怪的synchronized问题
- hibernate+jsf查询数据结果不稳定问题!谢谢。
- 求:google license key
这个查询语句写的有问题mu.menu.menuID这样不行,你可以用连接,虽然我数据库也学的不好,哈哈,我做毕业设计的时候hibernate查询遇到的问题也很多~~
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>
}