开发者

HQL Casting Error

I'm doing something like this

String SQL="From Auction auc where auc.AuctionId IN (:ids)";
            String BSQL="Select bid.auction.AuctionId From Bid bid where bid.User.UserId="+UserId;
            List <Long> UserBids=new LinkedList <Long>(session.createQuery(BSQL).list());
            System.out.println(UserBids.size());

            Query query = session.createQuery(SQL);
            query.setParameterList("ids", UserBids);


            List <Bid> AllBids=session.createQuery(SQL).setParameter("ids",query.list()).list();

and getting a casting error:

Caused by: java.lang.ClassCastException: java.util.LinkedList cannot be cast to java.lang.Long
    at org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap(LongTypeDescriptor.java:36)
    at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:52)
    at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
    at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)
    at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:571)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1716)
    at开发者_开发技巧 org.hibernate.loader.Loader.doQuery(Loader.java:801)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2533)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at com.BiddingSystem.server.ServiceImpl.getBid(ServiceImpl.java:1471)
    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)
    ... 21 more


I think the ClassCastException happens here

List <Bid> AllBids=session.createQuery(SQL).setParameter("ids",query.list()).list();

See: http://docs.jboss.org/hibernate/core/3.2/api/org/hibernate/Query.html#setParameterList%28java.lang.String%2C%20java.util.Collection%29

Isn't it enough to do (as you already set the parameter list):

List <Bid> allBids = (List<Bid>) query.list();

Cheers
Thomas

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜