我有以下测试代码
@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 中运行和生成行。
不幸的是,当我查看我的数据库时,没有任何内容被删除。知道为什么即使“已删除”表示删除了许多行,实际上什么也没删除?