我有以下测试代码
@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();
}
}
我的想法是每次测试运行时都使用SQL查询手动清理数据库。我有一堆@Test方法在表location_group中运行并生成行。
不幸的是,当我查看我的数据库时,没有任何内容被删除。任何想法为什么即使“删除”说删除了一些行实际上也没有?