Hades,Hibernate和JUnit:交易后没有发生持久性

时间:2011-03-12 06:13:00

标签: java hibernate jpa junit persistence

我有一个JUnit测试,需要在执行进一步操作并根据该列进行验证之前更新现有行的列。但我的问题是,即使在离开@Transactional边界后,列也没有得到更新。我的代码看起来有点像下面。

@RunWith(UnitilsJUnit4TestClassRunner.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 个答案:

没有答案