-
各位大佬们,想问个简单的事务问题: public ItemDTO create(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName, @RequestBody ItemDTO dto) {
Item entity = BeanUtils.transform(Item.class, dto);
ConfigChangeContentBuilder builder = new ConfigChangeContentBuilder();
Item managedEntity = itemService.findOne(appId, clusterName, namespaceName, entity.getKey());
if (managedEntity != null) {
throw new BadRequestException("item already exists");
}
entity = itemService.save(entity);
builder.createItem(entity);
dto = BeanUtils.transform(ItemDTO.class, entity);
Commit commit = new Commit();
commit.setAppId(appId);
commit.setClusterName(clusterName);
commit.setNamespaceName(namespaceName);
commit.setChangeSets(builder.build());
commit.setDataChangeCreatedBy(dto.getDataChangeLastModifiedBy());
commit.setDataChangeLastModifiedBy(dto.getDataChangeLastModifiedBy());
commitService.save(commit);
return dto;
} 在该方法中, |
Beta Was this translation helpful? Give feedback.
Answered by
nobodyiam
Dec 13, 2021
Replies: 1 comment 1 reply
-
I think it's better to mark this method with |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
iambiglee
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it's better to mark this method with
@Transactional
.