Hello,
I'm writing a Spring+Hibernate webapp. I'm running a simple unit test for testing DAO operations.
The test looks like so:
Code:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/test/resources/testSpringConfig.xml"})
@TransactionConfiguration(transactionManager="txManager")
@Transactional
public class BookingDaoTest {
@Autowired
private BookingDao dao;
private Booking testBooking;
@Before
public void beforeTest() {
testBooking = new Booking();
testBooking.setSomething("something");
// ...
dao.saveBooking(testBooking);
}
@Test
public void testDeleteBooking() {
int bookingId = testBooking.getBookingId();
dao.deleteBooking(testBooking);
Booking booking = dao.getBookingById(bookingId);
assertNull(booking);
}
}
Inside my BookingDaoImpl.deleteBooking method I have a single line:
Code:
getHibernateTemplate().delete(booking);
The test fails at the final assertion. So it appears that for some reason dao.deleteBooking is not working and I have no idea why. I added getHibernateTemplate().flush() invocation but it didn't help.
Also, I don't see the DELETE statement in Hibernate logs (though I see SELECT and INSERT statements).
Does anybody know what might be wrong and why the booking is not getting deleted?
Thanks a lot for any help!
Best regards,
Piotr