Мое решение этой проблемы заключалось в добавлении к контроллеру дополнительной функции, которая обновляла бы строку с помощью собственного оператора SQL. Так как мой код обновил часть или ключ (длинная история, но удивительно хорошо работала), я должен был убедиться, что не искал запись, основанную на новых значениях в pojo. вот код:
public void editSQLUpdate(Reportinfo reportinfo) throws NonexistentEntityException, Exception {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
String qry = "UPDATE `boeaudit`.`reportinfo` "
+ "SET "
+ "`author` = '" + reportinfo.getAuthor() + "',"
+ "`db_account` = '" + reportinfo.getDbAccount() + "',"
+ "`db_schema_name` = '" + reportinfo.getDbSchemaName() + "',"
+ "`descriptions` = '" + reportinfo.getDescriptions() + "',"
+ "`DLL` = '" + reportinfo.getDll() + "',"
+ "`parent_folder` = " + reportinfo.getParentFolder() + ","
+ "`path` = '" + reportinfo.getPath() + "',"
+ "`report_title` = '" + reportinfo.getReportTitle() + "',"
+ "`report_id` = " + reportinfo.getReportinfoPK().getReportId() + ","
+ "`env` = " + reportinfo.getReportinfoPK().getEnv() + ","
+ "`db_server` = '" + reportinfo.getReportinfoPK().getDbServer() + "',"
+ "`seq` = " + reportinfo.getReportinfoPK().getSeq()
+ " WHERE `report_id` = " + reportinfo.getReportinfoPK().getReportId()
+ " AND `env` = " + reportinfo.getReportinfoPK().getEnv()
+ " AND `db_server` = '-'" //this is the initial value of the record and the update value differs, so if we pass the new value the record will not be found. ;)
+ " AND `seq` = "+ reportinfo.getReportinfoPK().getSeq();
Query nq = em.createNativeQuery(qry);
int outcome = nq.executeUpdate(); //not doing anything with outcome, but should be used to determine the result of the operation...
em.getTransaction().commit();
} catch (Exception ex) {
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
ReportinfoPK id = reportinfo.getReportinfoPK();
if (findReportinfo(id) == null) {
throw new NonexistentEntityException("The reportinfo with id " + id + " no longer exists.");
}
}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
}