我真的陷入了这个错误
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.my.farmer.vo.crop.CropProfile#genus]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:145)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:179)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:557)
at org.hibernate.type.EntityType.resolve(EntityType.java:379)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1851)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2992)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:179)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:557)
at org.hibernate.type.EntityType.resolve(EntityType.java:379)
at org.hibernate.type.ComponentType.resolve(ComponentType.java:584)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:275)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:553)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:920)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:405)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:373)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:911)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:903)
at com.my.farmer.dao.impl.MarketDAOHibernateImpl.fetchMarket(MarketDAOHibernateImpl.java:46)
at com.my .farmer.bo.impl.MarketBOImpl.fetchMarket(MarketBOImpl.java:32)
at com.my.farmer.service.impl.MarketServiceImpl.triggerAdvisory(MarketServiceImpl.java:32)
at ClientSpringTester.main(ClientSpringTester.java:26)
我有三类作物,农作物和作物种类。
class crop{ cropId(PK), Cropprofile profile id (FK), Cropspecies speciesId(FK) }
class cropprofile{ profileid(pk), genus(unique), family }
class cropspecies{ speciesid(PK), Croprofile genus(FK) }
为了给你确切的错误来源,我有
class Marketfeed {
Crop cropId,
Market marketId }
在市场饲料中,cropId和marketId是综合关键。所以,当我做的时候
.find(来自Marketfeed市场)
生成此错误消息错误。我没有使用任何搜索条件。
有人可以提出此错误的可能原因吗?
答案 0 :(得分:4)
看起来您正在使用session.load(Object.class,id);
来解决此问题,您应该使用session.get(Object.class,id);
现在解释:
Session.load(Object.class,id)
- 返回对象代理,如果此对象不存在,则会抛出您获得的异常。
session.get(Object.class,id)
- 返回对象本身而不是其代理,如果此对象不存在则返回null。
希望它有所帮助。
答案 1 :(得分:2)
无论您尝试加载什么,数据库中都不存在您指定的主键。
答案 2 :(得分:0)
class crop{ profile id (FK), speciesId(FK) }
这听起来好像你引用了实体中的id,而你应该引用Objects:
@Entity
public class Crop{
@ManyToOne // or @OneToOne
private CropProfile profile;
@ManyToOne // or @OneToOne
private CropProfile profile;
// getters and setters omited
}