Hibernate version:3.1.1
Hey all
I am trying to test my first Hibernate application and have ran into some problems when deleting objects.
In my test class I have the following method
Code:
public void testDeletePerson() {
Person person = personDao.getPersonByUsername("person1");
personDao.delete(person);
}
This will throw the application into an infinite loop, ending with an java.lang.StackOverflowError which is caused in the following piece of code
Code:
public class PersonDAO extends AbstractDAO {
Log log = LogFactory.getLog(PersonDAO.class);
public PersonDAO() {
super();
}
public void delete(Person person) throws DAOException {
delete(person);
}
..
And here is the called method delete from the abstract class AbstractDAO
Code:
public abstract class AbstractDAO {
private Session session;
private Transaction tx;
..
protected void delete(Object obj) {
try {
startOperation();
session.delete(obj);
tx.commit();
} catch (HibernateException e) {
handleException(e);
} finally {
HibernateFactory.close(session);
}
}
My create and read methods work fine, it's the delete method which causes the test to crash. The debugger isn't giving me any ideas on what i'm doing wrong either as it calls the delete(Person person) in PersonDAO repeatedly until the java.lang.StackOverflowError occurs (the stacktrace is also just a bunch of calls to delete(Person person) and then StackOverFlowError). I also tried doing this in my test case:
Code:
Session session = HibernateFactory.openSession();
Person person = personDao.getPersonByUsername("person1");
session.delete(person);
But with no luck, the stackoverflowerror doesn's occur, but the row in the database fails to get deleted. Any ideas on why the test code is causing this infinite loop?
Thanks!