开发者

Object Not Found Exception in hibernate

开发者 https://www.devze.com 2023-04-09 08:41 出处:网络
I am really stuck at this error org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.my.farmer.vo.crop.CropProfile#genus]

I am really stuck at this error

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)  

I have three classes crop, cropprofile and cropspecies.

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) }    
开发者_如何学Python

To give you the exact source of error, I have

class Marketfeed  {  
Crop cropId,  
Market marketId  }  

In market feed cropId and marketId are composite key. So, when I do a .find(from Marketfeed market)

this error message error is generated. I am not using any search criteria.

Can anybody suggest possible causes of this error?


It looks like you are using session.load(Object.class,id); in order to solve this issue you should use session.get(Object.class,id);

Now the explaination:

Session.load(Object.class,id) - returns object proxy and in case and this object does not exist it throws the exception you are getting.

session.get(Object.class,id) - returns object itself instead od its proxy, if this object does not exist null returned.

Hope it helps.


Whatever you are trying to load does not exist in the database by the primary key that you are specifying.


class crop{ profile id (FK), speciesId(FK) }

This sounds like you have references to the ids in your entity, whereas you should have references to Objects:

@Entity
public class Crop{

    @ManyToOne // or @OneToOne
    private CropProfile profile;
    @ManyToOne // or @OneToOne
    private CropProfile profile;

    // getters and setters omited
}
0

精彩评论

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

关注公众号