【问题标题】:Getting hibernate error when using criteria使用条件时出现休眠错误
【发布时间】:2011-01-06 17:16:45
【问题描述】:

我有一个类项目和类别

Class Item
{
     private long ItemId;
     private String ItemName;
     private String ItemDescription;
     private String ItemWebSite;
     private String Condition;
     private long Price;
     private String Brand;
     private String AttributeDescription;
     private Category ProductCategory;
     private Set <Picture> Pictures= new HashSet <Picture>();
     //getters and setters
}

Class Category
{
        private long CategoryId;
    private String CategoryName;
    private Category ParentCategory;
    private Set <Category> SubCategory=new HashSet <Category> ();
    private Set <Attribute> AllAttributes= new HashSet  <Attribute>();
         //getters and setters
}

但是当我进行以下查询时:

long id=841;

Criteria crit =session.createCriteria(Item.class).add(Restrictions.eq("ProductCategory",id));

我收到此错误:

Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.BiddingSystem.Models.Category.CategoryId
    at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:198)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:230)
    at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3852)
    at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3560)
    at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
    at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:243)
    at org.hibernate.type.EntityType.getIdentifier(EntityType.java:449)
    at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:141)
    at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1769)
    at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1740)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
    at org.hibernate.loader.Loader.doList(Loader.java:2294)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
    at org.hibernate.loader.Loader.list(Loader.java:2167)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
    at com.BiddingSystem.server.ServiceImpl.UpdateCategory(ServiceImpl.java:799)
    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

【问题讨论】:

    标签: java hibernate hql


    【解决方案1】:

    使用这个:

    Criteria crit =session.createCriteria(Item.class).add(Restrictions.eq("ProductCategory.CategoryId",id));
    

    【讨论】:

      猜你喜欢
      • 2014-04-08
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 2020-07-14
      • 2013-07-06
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      相关资源
      最近更新 更多