org.hibernate.QueryException:无法解析属性:类似于:hibernetMappings.PostMessages

时间:2014-03-03 08:51:50

标签: hibernate hql

如何解决

org.hibernate.QueryException: could not resolve property: likeses of:  
hibernetMappings.PostMessages  

PostMessages.java

public class PostMessages  implements java.io.Serializable {
        private Long messageid;
         private String message;
         private String visibility;
         private String messageType;
         private Set likeses = new HashSet(0);
     //getter setter and constructors
    }

Likes.java

public class Likes  implements java.io.Serializable {

     private LikesId id;
     private Atom atom;
     private PostMessages postMessages;
     private Date adddate;
     private String status;
     private Date deleteTime;
    //getter setter and constructors
}

LikesId.java

public class LikesId  implements java.io.Serializable {
     private long messageid;
     private int aid;
//getter setter and constructors
}

Likes.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 1, 2014 11:04:39 AM by Hibernate Tools 3.6.0 -->
<hibernate-mapping>
    <class name="hibernetMappings.Likes" table="likes" catalog="xrcwrn_sms">
        <composite-id name="id" class="hibernetMappings.LikesId">
            <key-property name="messageid" type="long">
                <column name="messageid" />
            </key-property>
            <key-property name="aid" type="int">
                <column name="aid" />
            </key-property>
        </composite-id>
        <many-to-one name="atom" class="hibernetMappings.Atom" update="false" insert="false" fetch="select">
            <column name="aid" not-null="true" />
        </many-to-one>
        <many-to-one name="postMessages" class="hibernetMappings.PostMessages" update="false" insert="false" fetch="select">
            <column name="messageid" not-null="true" />
        </many-to-one>
        <property name="adddate" type="timestamp">
            <column name="adddate" length="19" not-null="true" />
        </property>
        <property name="status" type="string">
            <column name="status" length="20" />
        </property>
        <property name="deleteTime" type="timestamp">
            <column name="delete_time" length="19" not-null="true" />
        </property>
    </class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 20, 2014 2:22:34 PM by Hibernate Tools 3.6.0 -->
<hibernate-mapping>
    <class name="hibernetMappings.PostMessages" table="post_messages" catalog="xrcwrn_sms">
        <id name="messageid" type="java.lang.Long">
            <column name="messageid" />
            <generator class="identity" />
        </id>
        <property name="message" type="string">
            <column name="message" length="1000" />
        </property>
        <property name="visibility" type="string">
            <column name="visibility" length="100" />
        </property>

        <property name="messageType" type="string">
            <column name="message_type" length="20" />
        </property>
        <set name="likeses" table="likes" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="messageid" not-null="true" />
            </key>
            <one-to-many class="hibernetMappings.Likes" />
        </set>
    </class>
</hibernate-mapping>

我正在尝试关注hql

from PostMessages as pm
left join fetch pm.likeses as likes
where likes.id.messageid=67
and likes.id.aid=1

哪个显示错误

org.hibernate.QueryException: could not resolve property: likeses of: hibernetMappings.PostMessages [from hibernetMappings.PostMessages as pm
left join fetch pm.likeses as likes
where likes.id.messageid=67
and likes.id.aid=1]
        at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)
        at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75)
        at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1465)
        at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:315)
        at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:487)
        at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:611)
        at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:263)
        at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:210)
        at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:117)
        at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:380)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3671)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3452)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3325)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:733)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
        at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:256)
        at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:187)
        at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
        at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
        at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
        at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
        at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)

0 个答案:

没有答案