Java 如何使用OpenJPA从DB2数据库中选择前10条记录?

Java 如何使用OpenJPA从DB2数据库中选择前10条记录?,java,db2,openjpa,Java,Db2,Openjpa,我试图使用OpenJPA从DB2数据库中选择前10条记录。我正在尝试获取查询中指定的结果: SELECT * FROM CACHE_REFRESH_TABLE FETCH FIRST 10 ROWS ONLY 为此,我在persistence.xml中启用了以下属性 <property name="openjpa.jdbc.DBDictionary" value="db2(SupportsSelectStartIndex=true,SupportsSelectEndIndex=true)

我试图使用OpenJPA从DB2数据库中选择前10条记录。我正在尝试获取查询中指定的结果:

SELECT * FROM CACHE_REFRESH_TABLE FETCH FIRST 10 ROWS ONLY
为此,我在
persistence.xml
中启用了以下属性

<property name="openjpa.jdbc.DBDictionary" value="db2(SupportsSelectStartIndex=true,SupportsSelectEndIndex=true)"/>
下面是Java代码

public List<CacheHistoryOTO> fetchRefreshHistory(
                int someInput1, String someInput2) throws SomeException {
            LOGGER.info(EventMessages.METH_START, "fetchRefreshHistory");
            List<CacheHistoryOTO> cacheHistoryOTOList = null;
            try {
                EntityManager entityManager = entityManagerProvider
                        .getEntityManager();
                final Query query = entityManager
                        .createNamedQuery("topHistoryRecords");
                query.setMaxResults(someInput1);//Depending on parameter someInput1 number of records to be fetched will be provided.

                cacheHistoryOTOList = (List<CacheHistoryOTO>) query
                        .getResultList();
            } catch (Exception e) {
                LOGGER.error(EventMessages.ERROR, e);
                throw new SomeException(Constant.ERROR_PERSISTENCE, e);
            }
            LOGGER.info(EventMessages.METH_END, "fetchRefreshHistory");
            return cacheHistoryOTOList;
    }
有人能建议用正确的方法来做这件事吗


我已经看过了,但没有帮助。

对我来说似乎是一个方言问题<代码>前10名是我希望在SQL Server中看到的东西。您可以共享数据源设置吗?
public List<CacheHistoryOTO> fetchRefreshHistory(
                int someInput1, String someInput2) throws SomeException {
            LOGGER.info(EventMessages.METH_START, "fetchRefreshHistory");
            List<CacheHistoryOTO> cacheHistoryOTOList = null;
            try {
                EntityManager entityManager = entityManagerProvider
                        .getEntityManager();
                final Query query = entityManager
                        .createNamedQuery("topHistoryRecords");
                query.setMaxResults(someInput1);//Depending on parameter someInput1 number of records to be fetched will be provided.

                cacheHistoryOTOList = (List<CacheHistoryOTO>) query
                        .getResultList();
            } catch (Exception e) {
                LOGGER.error(EventMessages.ERROR, e);
                throw new SomeException(Constant.ERROR_PERSISTENCE, e);
            }
            LOGGER.info(EventMessages.METH_END, "fetchRefreshHistory");
            return cacheHistoryOTOList;
    }
@NamedQueries({
        @NamedQuery(name = "topHistoryRecords", query = "SELECT cacheRefreshHistoryOTO FROM CacheHistoryOTO cacheRefreshHistoryOTO ORDER BY cacheRefreshHistoryOTO.refreshTimeStamp DESC")
        })