【问题标题】:Eclipselink - JPA 2.0 - Select with lockMode and maxResult doesn't workEclipselink - JPA 2.0 - 使用 lockMode 选择并且 maxResult 不起作用
【发布时间】:2014-11-11 07:34:25
【问题描述】:
@Override
public List<Sample> getSampleRecords() {
    List<Sample> samples = null;
    try {

        Query query = entityManager
                .createQuery(
                        "from Sample s order by s.createdAt desc")
                .setLockMode(LockModeType.PESSIMISTIC_WRITE);
         query.setMaxResults(100);
        samples = query.getResultList();
    } catch (Exception exceptionGetSample) {
        logger.error("Exception while retrieving the records", exceptionGetSample);

    }
    return samples;
}

当我用 oracle db 执行它时发生错误:

Caused by: org.eclipse.persistence.exceptions.DatabaseException:
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis
  1. 如果我只使用 lockmode 参数执行它,则不会发生错误。
  2. 如果我只使用 maxResult 参数执行它,则不会发生错误。

我用过 eclipselink 2.5.0 库。

请提出一些方法,以便我可以同时使用锁定以及使用 setMaxResults 限制记录。

【问题讨论】:

  • 是否产生SQL语句?如果有,生成的 SQL 语句是什么?
  • @Tiny Query: ReadAllQuery(referenceClass=Sample sql="SELECT * FROM (SELECT /*+ FIRST_R OWS /a., ROWNUM rnum FROM (SELECT ID AS a1, CREATEDAT AS a2, NAME AS a3 FROM ssohub.Sample ORDER BY CREATEDAT DESC FOR UPDATE) a WHERE ROWNUM ?")

标签: java orm eclipselink jpa-2.0


【解决方案1】:

请参阅以下链接以获取该问题的临时解决方案 https://bugs.eclipse.org/bugs/show_bug.cgi?id=453208#c7

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 2011-12-04
    • 2016-06-03
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多