我正在处理Spring声明式事务处理赋值。
我的问题是,数据在交易过程中处于中间位置。我只使用'new'运算符将数据设置为新创建的对象。为了设置数据我点击DB并且必须获取一些数据。在执行setter方法的一半方法后,它会刷新一些数据
例如:
联系contact = DB.loadContact(); - >选择查询
Consignment.setContact(contact);
- >当执行通过此行时,数据将提交到DB
请参阅以下代码以进一步了解
// code 01
@Transactional(propagation=Propagation.REQUIRES_NEW, rollbackFor=Exception.class)
public void editInternationalExportConsigment (){
// calling a nested method
internationalExportConnoteFormToDomainTranslator.translate(exportConssignmentWrapper, user);
..........
}
//code 02
@Transactional(propagation=Propagation.SUPPORTS)
public InternationalConsignment translate(AbstractFormWrapper defaultWrapper, Person user) {
// set values to a newly created object
consignment.setSenderContact(contact);
consignment.setCustomerReference(consignmentVO.getCustomerRef());
// I have called no insert or update calls in the middle,
//There are only select queries hit the db middle in the process and those also execute under transactional scope.
Contact contact =
inquiry.loadCustomerContactById(consignmentVO.getCustomerContactId().intValue());
// when executing this line, it commit the Data to DB
consignment.setContact(contact);
...........
...........
}
我使用以下方式监控交易,并且记录器通过流程显示相同的活动交易
logger.error("######Method Name ==="+str+"==="+ Thread.currentThread().getStackTrace());
logger.error("######Transaction Name ==="+str+"==="+TransactionSynchronizationManager.getCurrentTransactionName());
logger.error("######Transaction Active ==="+str+"==="+TransactionSynchronizationManager.isActualTransactionActive());
logger.error("######Transaction Readonly ==="+str+"==="+ TransactionSynchronizationManager.isCurrentTransactionReadOnly())
我被困在这里,非常感谢有人能在这里给我一个线索。
谢谢!
---详细的代码块我有问题 -
private void translateOrginDestinationInformation(InternationalExportConsignmentFormWrapper consignmentVO, InternationalConsignment consignment, ISVCAIXISInquiry inquiry) {
Country destination = inquiry.loadCountryById(consignmentVO.getReceiverCountryID());
consignment.setDestination(destination);
consignment.setDestinationCity(inquiry.loadByCityId(consignmentVO.getReceiverCityID()));
TestTransactionIndicatingUtil.testTransactionalStatus("originaldestination translate");
Contact contact = inquiry.loadCustomerContactById(consignmentVO.getCustomerContactId().intValue());
if (contact != null && contact.getCity() != null) {
consignment.setOrgin(contact.getCity().getCountry());
consignment.setUniqueOriginCountry((contact.getCity().getCountry()!=null)?contact.getCity().getCountry().getId():null);
consignment.setOrginCity(contact.getCity());
}
}