Ошибка при написании Hibernate HQL - PullRequest
0 голосов
/ 10 февраля 2011

Я тестирую следующий hql, но получаю сообщение об ошибке

String SQL="From Bid bid where bid.Auction.AuctionId=3655"

Файл сопоставления ставок класса:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jan 19, 2011 5:25:35 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
    <class name="com.BiddingSystem.Models.Bid" table="BID">
        <id name="BidId" type="long">
            <column name="BIDID" />
            <generator class="native" />
        </id>
        <property name="BidAmount" type="long">
            <column name="BIDAMOUNT" />
        </property>
        <many-to-one name="User" class="com.BiddingSystem.Models.Users" fetch="join">
            <column name="UserId" />
        </many-to-one>
        <many-to-one name="auction" class="com.BiddingSystem.Models.Auction" fetch="join" lazy="false">
            <column name="AuctionId" />
        </many-to-one>
        <property name="TimePosted" type="java.util.Date" access="field">
            <column name="TIMEPOSTED" />
        </property>
    </class>
</hibernate-mapping>

Файл сопоставления аукциона:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 28, 2010 9:14:12 PM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
    <class name="com.BiddingSystem.Models.Auction" table="AUCTION">
        <id name="AuctionId" type="long">
            <column name="AUCTIONID" />
            <generator class="native" />
        </id>
        <property name="StartTime" type="java.util.Date">
            <column name="STARTTIME" />
        </property>
        <property name="EndTime" type="java.util.Date">
            <column name="ENDTIME" />
        </property>
         <property name="DatePlaced" type="java.util.Date">
            <column name="DatePlaced" />
        </property>
        <property name="StartingBid" type="long">
            <column name="STARTINGBID" />
        </property>
        <property name="MinIncrement" type="long">
            <column name="MININCREMENT" />
        </property>
        <many-to-one name="CurrentItem" class="com.BiddingSystem.Models.Item" fetch="join" not-null="true" cascade="all" unique="true" lazy="false">
            <column name="CURRENTITEM" />
        </many-to-one>

        <property name="AuctionStatus" type="java.lang.String">
            <column name="AUCTIONSTATUS" />
        </property>
        <property name="BestBid" type="long">
            <column name="BESTBID" />
        </property>
        <many-to-one name="User" class="com.BiddingSystem.Models.Users" fetch="join">
            <column name="UserId" />
        </many-to-one>
    </class>
</hibernate-mapping>

Ошибка:

Caused by: org.hibernate.QueryException: could not resolve property: Auction of: com.BiddingSystem.Models.Bid [From com.BiddingSystem.Models.Bid bid where bid.Auction.AuctionId=3655 and bid.User.UserId=3657]
    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:1449)
    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.DotNode.resolveFirstChild(DotNode.java:175)
    at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:571)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4774)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1326)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4471)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3944)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2047)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1972)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:831)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:617)
    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:254)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
    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)
    at com.BiddingSystem.server.ServiceImpl.getBid(ServiceImpl.java:1463)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:174)

Ответы [ 2 ]

2 голосов
/ 10 февраля 2011

Исходя из вашего Bid файла отображения, ваш SQL должен выглядеть следующим образом: -

String SQL="From Bid bid where bid.auction.AuctionId=3655"

А если серьезно, ваша верблюжья оболочка в ваших бобах действительно запутана.Имена свойств в вашем bean-компоненте ДОЛЖНЫ начинаться с маленькой буквы (например: auctionId, auction, timePosted и т. Д.).

1 голос
/ 10 февраля 2011

Бьюсь об заклад, это будет работать

String SQL="From Bid bid where bid.auction.auctionId=3655"

Свойства должны всегда начинаться со строчных букв в Java.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...