hibernate / Java:无法添加或更新子行:外键约束失败

时间:2012-04-23 13:50:25

标签: java mysql hibernate

我有这些实体类

PlayerProfileEntity& UserInfoEntity

我加入了userInfoEntity& PlaterProfileEntity并将我的记录保存在数据库中,如下所示:

Session session = sessionFactory.openSession();
Transaction tr = session.beginTransaction();
Criteria crit = session.createCriteria(PlayerProfileEntity.class);
player.setUserId(new UserInfoEntity());
player.getUserId().setAddress(user.getUserId().getAddress());

session.save(player);
tr.commit();

我在我的PlayerProfileEntity类中使用了这个assosiation

@ManyToOne (fetch = FetchType.LAZY)
@Cascade({CascadeType.ALL})
@JoinColumn(name="userid")
private UserInfoEntity userId;

我收到此错误:

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`cricdb`.`userinfo`, CONSTRAINT `FK_teamInfo` FOREIGN KEY (`teamId`) REFERENCES `teaminfo` (`TeamId`))

任何解决方案?

0 个答案:

没有答案