无法删除或更新父行ConstraintViolationException

无法删除或更新父行ConstraintViolationException,第1张

无法删除或更新父行ConstraintViolationException

尝试使用

entityManager.createNativeQuery()
。您不能使用,
createQuery()
因为该表应该作为实体存在于Java代码中。另外,您需要使用确切的SQL格式。

String query = "DELETe FROM USER_PHONE WHERe user_id=?1";

    try{        Query q = entityManager.createNativeQuery(query);        q.setParameter(1,id);        q.executeUpdate();        System.out.println(System.currentTimeMillis() + " DELETE User_Phone: userId " + id + " ==> deleted");    } catch(Exception e){        e.printStackTrace();        return false;    }`

首先从

USER_PHONE
(使用
createNativeQuery()
)删除行,然后从
User
(使用
createQuery()
)删除行



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5621857.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存