开发者

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);   
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜