Spring Transaction,Hibernate和INSERT语句与FOREIGN KEY约束冲突

时间:2013-10-09 06:48:26

标签: java sql spring hibernate

我想知道为什么我的代码会给我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;
    }
}

0 个答案:

没有答案