-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.ObjectNotFoundException while using Get
PostPosted: Wed Mar 14, 2012 9:32 am 
Newbie

Joined: Mon May 31, 2010 4:38 am
Posts: 3
org.hibernate.ObjectNotFoundException while using Get

Get method in hibernate returns null if no row is found for given ID.
My understanding is that ObjectNotFoundException is thrown by hibernate while proxy returned by load is accessed and there is no row found for given ID. But i am getting this exception while using get(). Please let me know if any one you have faced this issue.

org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException: No row with the given identifier exists: [com.data.PersonDO#com.data.PersonId@348515a3]; nested exception is org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.data.PersonDO#com.data.PersonId@348515a3]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:663)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:512)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:506)
.....................................
Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.data.PersonDO#com.data.PersonId@348515a3]
at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:447)
at org.hibernate.event.def.DefaultLoadEventListener.returnNarrowedProxy(DefaultLoadEventListener.java:320)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:277)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1080)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:997)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:990)
at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:519)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
... 185 more



In my product we are using hibernate-core 3.5.1 and Spring 3.0.2.jar .
We are calling get method of Spring hibernate template .


We are calling hibernates session.get() method by using org.springframework.orm.hibernate3.HibernateTemplate.get(Class<Object>, Serializable)


public Object findObject(Class class, Serializable id) throws HibernateException {
return (Object) getHibernateTemplate().get(class, id);
}


Top
 Profile  
 
 Post subject: Re: org.hibernate.ObjectNotFoundException while using Get
PostPosted: Wed Oct 09, 2013 3:37 am 
Newbie

Joined: Wed Oct 09, 2013 3:26 am
Posts: 1
I have the same issue, i reduce the problem to this simple case reproducing the exception :

Mapping : (standard mapping, found in https://docs.jboss.org/hibernate/orm/3.3/reference/fr-FR/html/associations.html)
Code:
<class name="Person" table="tperson">
<id name="id" column="personpk">
<generator class="native"/>
</id>
<set name="addresses"
table="personaddress">
<key column="personid"/>
<many-to-many column="addressid"
unique="true"
class="Address"/>
</set>
</class>

<class name="Address" table="taddress">
<id name="id" column="addresspk">
<generator class="native"/>
</id>
<join table="personaddress"
inverse="true"
optional="true">
<key column="addressid"/>
<many-to-one name="person"
column="personid"
not-null="true"/>
</join>
</class>


Classes :
Code:
public class Address {
  private Long id;
  private Person person;
  public Address() {}
  public Address(Long id) {
    this.id = id;
  }
  public void setPerson(Person person) {
    this.person = person;
  }
}
public class Person {
  private Long id;
  private Collection<Address> addresses;
  public Person() {}
  public Person(Long id) {
    this.id = id;
  }
  public void addAddress(Address address) {
    if (addresses == null) {
      addresses = new HashSet<Address>();
    }
    addresses.add(address);
  }
}


Test :
Code:
//create conditions
Transaction transaction = session.session.beginTransaction();
Person person = new Person(idPers);
Address address = new Address(idAddr);
address.setPerson(person);
person.addAddress(address);
session.save(person);
session.save(address);
transaction.commit();
session.clear();

//Now, reproduction of problem
session.beginTransaction();

//this call is necessary for reproduction of problem
session.get(Address.class, idAddr);

Person reloadedPerson = (Person) session.get(Person.class, idPers);
session.delete(reloadPerson);

//Here the exception
Person expectedNullPerson= (Person) session.get(Person.class, idPers);


Calling session.get(Address.class, idAddr); make reloadedPerson a javassit, when it is not called, "expectedNullPerson" is null like expected.

[Edit] We use hibernate 4.1.11 but i also reproduce it with hibernate 4.2.0


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.