1

我想知道为什么我的代码给了我The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tbl_bo_gui_group_user_tbl_bo_gui_user". The conflict occurred in database "IVRBODBDEV", table "dbo.tbl_bo_gui_user", column 'id'..

我已经添加了@Transactional注释,因为另一个 DAO 正在处理连接表的记录插入。

@Override
@Transactional
public void addUser(User user, String[] group, String createdBy) throws Exception {
    String userId = getUserDao().addUser(user, createdBy);

    getGroupUserDao().addGroupUser(userId, group, createdBy);
}

addUser课堂上UserDaoImpl

@Override
public String addUser(User user, String createdBy) throws Exception {
    try {
        log.info("Adding user...");

        user.setDateCreated(DateUtil.getDateTime());
        user.setCreatedBy(createdBy);

        getCurrentSession().save(user);

        return user.getId();
    } catch(Exception e) {
        log.error("Adding user failed. MESSAGE: " + e.getMessage());
        throw e;
    }
}
4

0 回答 0