Hades,Hibernate and JUnit: Persistence not happening after transaction
I have a JUnit test that needs to update a column of an existing row before further operations are performed and validated based on that column. But my problem is that column is not getting updated even after leaving the @Transactional boundary. My code looks kind of like below.
@RunWith(UnitilsJUnit4TestClassRunn开发者_如何转开发er.class)
@SpringApplicationContext(
{ "applicationContext.xml" })
public class TestClass
{
@SpringBeanByType
TestTableDBUtil util;
@Test
public void test()
{
util.updateColumnA(id, true);
/* I do not see the column A value commited on returning from this function */
/* Operations and validations based on the updated column ensue */
}
}
@Component
@ContextConfiguration(locations =
{ "/applicationContext.xml" })
@TransactionConfiguration
public TestTableDBUtil
{
@Autowired
private MyTableRepository myTableRepo;
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void updateColumnA(Long id, boolean value)
{
MyEntity myEntity = myTableRepo.readByPrimaryKey(id);
myEntity.setColumnA(value);
myTableRepo.saveAndFlush(myEntity);
}
}
精彩评论