【问题标题】:I cannot see the update record after flush刷新后看不到更新记录
【发布时间】:2019-10-05 08:43:30
【问题描述】:

从 glassfish3 传递到 payara5 一段代码停止工作。我们的代码将日期保存到一组记录并选择那些更新的记录。在 glassfish3 中无缝工作,在 payara5 中,选择不返回任何记录(似乎它确实在另一个事务中工作)。如果结果不同,我们会抛出异常,因此永远不会保存数据。 事务范围为 READ_COMMITTED

            try {
                String whereClause = " where "
                    + "em.mailboxToBeUsed =:mailbox "
                    + "and em.lastSendResult is null "
                    + "and (em.errorsNumber is null or em.errorsNumber<4) ";

                Query updateQuery = em.createQuery("update EmailTobeSended em "
                    + "set em.trysendsince=:dat " + whereClause);

                updateQuery.setParameter("mailbox", mb);
                updateQuery.setParameter("dat", key);

                int modificate = updateQuery.executeUpdate();
                em.flush();
                TypedQuery<EmailTobeSended> emlocksel = em.createQuery(
                    "select em from EmailTobeSended em WHERE em.mailboxToBeUsed =:mailbox AND "
                    + "em.trysendsince=:dat "
                    + " order by em.emailId ", EmailTobeSended.class);
                emlocksel.setParameter("mailbox", mb);
                emlocksel.setParameter("dat", key);

                res = emlocksel.getResultList();
                if (modificate != res.size()) {
                    throw new java.lang.AssertionError("Lock error on select emailtobesended");
                }

            } catch (Exception ex) {
                gotError = true;
                res = null;
            }

在 glassfish3 上,刷新后,第二个查询找出更新的记录。在payara5上没有结果

编辑


我们使用eclipselink

【问题讨论】:

  • @Karan Sethi :似乎它们与休眠有关,而不是 eclipselink 我们在函数上没有注释
  • 任何我希望看到的建议
  • 这个问题不清楚结果是什么。修改的值是什么,返回的 res 列表中有什么?我能看到这种情况发生的唯一方法是 EntityManager 不是事务的一部分,但这会导致 em.flush() 调用引发异常。否则,这是您的服务器中的配置问题或错误,您需要展示如何获取 EntityManager 和事务

标签: java jpa eclipselink payara


【解决方案1】:

我们解决了这个问题:这不是关于持久性,而是关于 mysql 版本(从 5.5 到 5.6) DATE 字段在两个版本之间的解释不同:在 5.5 毫秒内被忽略,在 5.6 中被考虑。由于该字段未配置为接受毫秒,因此在没有它们的情况下保存了日期,因此在第二个查询(选择)中,比较完成了“.000”作为毫秒的回答,与搜索的不同 将字段更新为 DATE(3) 解决了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 2014-10-17
    • 2016-12-24
    • 2017-10-18
    相关资源
    最近更新 更多