An ObjectNotFound exception is thrown trying to access to a deleted object.
//Creation
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.
|