On 19/02/2015 13:38, c.whalley wrote: > On 19/02/2015 02:36, Nam Nguyen wrote: >> Hi Carl, >> >> JPA prohibits changing the primary key. So you're right about having >> to do a copy-and-delete. I'm not too familiar with EclipseLink - >> what's the exact error you're seeing? Maybe others can chime in. >> >> Anyways, I think the easiest and most effective way is to just use >> plain-ole SQL. >> >> -- Nam > Thanks. Or even a pointer to a better (active) place to ask? Already > done SO. Pretty sure its a pure JPA question though. > > -- Carl > > > _______________________________________________ > resin-interest mailing list > resin-interest@caucho.com > http://maillist.caucho.com/mailman/listinfo/resin-interest > After further thought I fixed this, so here it is for completeness:
userWithSameRegId = findUserFromRegId(userToPersist.getGCM_Dev_Reg_Id()); if (userWithSameRegId != null) { log.fine(s+"RegID Existed as: " + userWithSameRegId.getName()); // We're "changing the primary key" by cloning and deleting the rec. user = new User(); user.setName(userToPersist.getName()); user.setGCM_Dev_Reg_Id(userToPersist.getGCM_Dev_Reg_Id()); user.setGCM_Reg_Count(userWithSameRegId.getGCM_Reg_Count() + 1); // Now delete the original rec try { Query userToDeleteQuery = em.createQuery("select u from User u where u.name = ?1"); userToDeleteQuery.setParameter(1, userWithSameRegId.getName()); User userToDelete = null; try { userToDelete = (User) userToDeleteQuery.getSingleResult(); em.remove(userToDelete); } catch (NoResultException nre) { } } catch (Exception e) { e.printStackTrace(); } _______________________________________________ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest