1

I have the following test code

@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class LocationGroupControllerTest extends JerseyTest {

    private static final String FAKE_GROUP_NAME = "fake data 11e5-9730-9a79f06e9478 - ";

    @Autowired
    private ILocationGroupService iLocationGroupService;


    @Autowired
    @Qualifier("sessionFactory")
    private SessionFactory sessionFactory;

    @Before
    @Rollback(false)
    @Transactional(readOnly = false)
    public void setup() {
        {
            int deleted = sessionFactory.getCurrentSession().createSQLQuery("DELETE FROM location_group WHERE GROUPNAME LIKE :fakeGroupName")
                    .setString("fakeGroupName", FAKE_GROUP_NAME + "%")
                    .executeUpdate();
        }
    }

The idea is I manually cleanup the database using a SQL query each time the test runs. I have a bunch of @Test methods that run and generate rows in the table location_group.

Unfortunetly when I look in my database nothing is being deleted. Any idea why even though "deleted" says a number of rows were deleted nothing actually was?

benstpierre
  • 32,833
  • 51
  • 177
  • 288

0 Answers0