Hi, I am doing some tests (see the code below), I instantiate a new Worker object, set some properties, save it, delete it and after the deletion try to retrieve it from the database.
I was expecting a null pointer returned but get a ObjectDeletedException.
The first time, I was using the load method (session) but I red I should use this method only for objects that I am sure they exist, so I replace the load method by the get method but the result is the same...
Thank you
Best regards
Lilian
Hibernate version:
3.0
JUnit test method:
Code:
public void testSaveOneWorker()
{
Worker john = new Worker();
assertNull( john.getId() );
john.setAffiliationDate( new Date() );
john.setWorkPermitCode( "worker.permit.ch" );
dao.save( john );
assertNotNull( john.getId() );
Integer johnId = john.getId();
dao.delete( john );
john = dao.getWorkerById( johnId, false );
assertNull( john );
}
the getWorkerById method:Code:
Session session = HibernateUtil.currentSession();
Worker worker = null;
try
{
if ( lock )
{
worker = (Worker)session.get( Worker.class, workerId, LockMode.UPGRADE );
}
else
{
worker = (Worker)session.get( Worker.class, workerId );
}
}
catch ( HibernateException ex )
{
throw new InfrastructureException( ex );
}
return worker;
Full stack trace of any exception that occurs:
11:23:19,398 INFO DefaultLoadEventListener:129 - Error performing load command
org.hibernate.ObjectDeletedException: The object with that id was deleted: [bab.admin.model.persistent.Worker#10]
at org.hibernate.event.def.DefaultLoadEventListener.loadFromSessionCache(DefaultLoadEventListener.java:430)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:210)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
at bab.admin.model.dao.WorkersDAO.getWorkerById(WorkersDAO.java:49)
at bab.admin.model.dao.WorkersDAOTests.testSaveOneWorker(WorkersDAOTests.java:50)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Name and version of the database you are using:
MySQL 4.1
The generated SQL (show_sql=true):
Hibernate: insert into t_party (comment, partyType) values (?, 'worker')
Hibernate: insert into t_avs (cotiseYN, avsNumber, requestDate, expeditionDate, receptionDate, partyId) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into t_person (sex, title, maritalStatusCode, birthdate, accountInfo, firstname, lastname, partyId) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into t_worker (enabledYN, critic, compliment, motivationCode, motivationShortCode, affiliationDate, lastReactivationDate, workPermitCode, authorizationExpirationDate, sourceYN, activityId, partyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into t_workerDisponibility (mondayMorningYN, mondayAfternoonYN, mondayNightYN, tuesdayMorningYN, tuesdayAfternoonYN, tuesdayNightYN, wednesdayMorningYN, wednesdayAfternoonYN, wednesdayNightYN, thursdayMorningYN, thursdayAfternoonYN, thursdayNightYN, fridayMorningYN, fridayAfternoonYN, fridayNightYN, saturdayMorningYN, saturdayAfternoonYN, saturdayNightYN, sundayMorningYN, sundayAfternoonYN, sundayNightYN, februaryYN, paquesYN, summerYN, autumnYN, noelYN, jeunegenevoisYN, ascensionYN, pentecoteYN, partyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update t_worker set enabledYN=?, critic=?, compliment=?, motivationCode=?, motivationShortCode=?, affiliationDate=?, lastReactivationDate=?, workPermitCode=?, authorizationExpirationDate=?, sourceYN=?, activityId=? where partyId=?