有个BookComment类的映射文件如下
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="org.brucefeng.sinter.domain"> <class name="BookComment" table="comment"> <id name="bookCommentPK" column="commentpk"> <generator class="uuid.hex"></generator> </id> <property name="title" type="string" column="title"></property> <property name="content" type="text" column="content"></property> <many-to-one name="author" column="userpk" class="org.brucefeng.sinter.domain.User" cascade="save-update" fetch="join" lazy="false"></many-to-one> </class> </hibernate-mapping>
在查询的时候使用下列语句
String hql = "from BookComment as bc where bc.userpk=:author order by bc.title asc";
执行代码时出现如下问题:
org.hibernate.QueryException: could not resolve property: userpk of: org.brucefeng.sinter.domain.BookComment [from org.brucefeng.sinter.domain.BookComment as bc where bc.userpk=:author order by bc.title asc]
谢谢。
问题补充:
当将hql语句修改为
String hql = "from BookComment where userpk=:author order by title asc
后可以顺利查询出结果