gpt4 book ai didi

java - 使用标准时出现 hibernate 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:22 25 4
gpt4 key购买 nike

我有一个类 Item 和 Category

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

最佳答案

使用这个:

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

关于java - 使用标准时出现 hibernate 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4617643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com