我正在尝试更新存储在数据库表中的值。 但我收到错误“没有给定标识符的行存在:[此实例尚未作为数据库#3中的行存在]”
我正在尝试运行的代码
public Integer findPersonXHrUserId(String nic)
{
Query query = em.createQuery("select u.userId from XHrUser u where (u.nic) = (:nic)")
.setParameter("nic", nic);
List<Integer> list = query.getResultList();
return list.isEmpty() || list.get(0) == null ? 0 : list.get(0);
}
public void UpdateUserInDbTable(String firstName, String lastName, String nic, String phoneNumber, String emailAddress) {
int userId = findPersonXHrUserId(nic);
XHrUser xHrUserObj= new XHrUser();
xHrUserObj.setUserId(userId);
xHrUserObj.setFirstName(firstName);
xHrUserObj.setLastName(lastName);
xHrUserObj.setNic(nic);
xHrUserObj.setPhone(phoneNumber);
xHrUserObj.setEmail(emailAddress);
em.persist(xHrUserObj);
xHrUserObj= em.find(XHrUser.class, xHrUserObj.getUserId());
em.merge(xHrUserObj);
em.refresh(xHrUserObj);
}
由于
答案 0 :(得分:0)
我删除了坚持并且它有效..