小编use*_*624的帖子

org.springframework.dao.DataIntegrityViolationException:具有相同标识符值的不同对象已经与会话相关联

此方法以事务开头

@Transactional(propagation = Propagation.REQUIRED)
public Account generateDirectCustomerAccountEntity(AccountReq source, Map<String, String> headers, String workflowId) {
    Account dbAccount = dCustomerModelToEntityMapper.map(source, headers);
    dbAccount = saveAccount(source, dbAccount, headers, workflowId);
    return dbAccount;
}   
Run Code Online (Sandbox Code Playgroud)

这是一个映射器类,我在其中创建 DB Account 实体并映射 address 和 contacts 。

@Override
@LogExecutionTime(log=true)
public Account map(AccountReq accountReq, Map<String, String> headers) {
        logger.info("AccountModelToEntityMapper.mapDirectCustomer*****START");
        Account dbAccount = new Account();
        AccountCode accountCode = dbService.getAccountCodeForDirectCustomer(accountReq);
        String accountId = dbService.genarateAccountId(accountCode);
        logger.info("genarated AccountID for Direct Customer is={}", accountId);
        dbAccount.setAccountId(accountId);
        setAccountContact(dbAccount, accountReq, headers);
        setAddress(dbAccount, accountReq);
        dbAccount.setAccountType(accountCode.getCodeId());
        return dbAccount;
}
Run Code Online (Sandbox Code Playgroud)

当我不在地图内调用下面的方法时,一切正常。但是当我调用它时,我得到了标题中描述的错误。

private void …
Run Code Online (Sandbox Code Playgroud)

session jpa transactions

0
推荐指数
1
解决办法
2403
查看次数

标签 统计

jpa ×1

session ×1

transactions ×1