我正在尝试运行与我的资源类相关的测试用例,我在其中添加了@Transactional注释。
资源类对oracle数据库上的操作有常规的创建,更新,删除方法,但我的测试用例失败了。
代码是: -
资源类: -
@Transactional
public class TestToSAVE {
@ApiOperation(value = "Create new information store definition", notes = "Create a new information store definition and return with its unique id", response = InformationStoreDefinition.class)
@POST
@Timed
public void create() {
//code for create object and save into database
}
测试用例代码: -
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {TestConfiguration.class})
@Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor = TransactionException.class)
public class TestToSAVETest {
//code in test class
}
例外:
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
请建议我如何解决此异常。