Java Hibernate条件。setMaxResults()在Oracle 11g上失败

Java Hibernate条件。setMaxResults()在Oracle 11g上失败,java,oracle,hibernate,pagination,paging,Java,Oracle,Hibernate,Pagination,Paging,使用hibernate从Oracle 11g DB检索数据时,请使用org.hibernate.dialen.oracle10galent或org.hibernate.dialent.oraclealent 我得到以下信息: org.hibernate.exception.SQLGrammarException: could not execute query Caused by: java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword

使用hibernate从Oracle 11g DB检索数据时,请使用org.hibernate.dialen.oracle10galentorg.hibernate.dialent.oraclealent 我得到以下信息:

org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword not found where expected
查看日志,我们可以看到查询:

select top ? this_.LI_ILN as LI1_8_0_, this_.COUNTRY_CODE ... 
显然,数据库无法识别关键字,这就是问题所在,因为在Oracle中,只能使用ROWNUM进行分页,Hibernate应该知道这一点

hibernate配置如下所示:

<hibernate-configuration>
<session-factory name="HibernateSessionFactory">
    <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
    <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="hibernate.connection.password">...</property>
    <property name="hibernate.connection.url">...</property>
    <property name="hibernate.connection.username">...</property>
    <property name="hibernate.default_schema">...</property>
    <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
    <property name="hibernate.search.autoregister_listeners">false</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.hbm2ddl.auto">validate</property>
    <property name="hibernate.transaction.auto_close_session">false</property>

    <mapping resource="HB_Mappings/Supplier.hbm.xml" />
</session-factory>

假的
oracle.jdbc.OracleDriver
...
...
...
...
org.hibernate.dialen.oraclealent
假的
真的
验证
假的

查询是这样完成的:

Criteria crit = sessionFactory.getCurrentSession().createCriteria(Supplier.class);
crit.setFirstResult(50 * pageIndex);
crit.setMaxResults(50);

List<Supplier> list = crit.list();
Criteria crit=sessionFactory.getCurrentSession().createCriteria(Supplier.class);
临界值setFirstResult(50*pageIndex);
临界setMaxResults(50);
List=crit.List();
感谢您的帮助


已解决:

忘了提到我正在使用spring,其中applicationContext.xml如下所示:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation">
        <value>classpath:HB_Mappings/hibernate.cfg.xml</value>
    </property>
    <property name="hibernateProperties">
        <value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
    </property>
</bean>

类路径:HB_映射/hibernate.cfg.xml
hibernate.dialogue=org.hibernate.dialogue.hsql方言
它重写了hibernate.cfg.xml的属性


self注意:轻松复制粘贴

不推荐使用Oracle方言,请参见此处:

请改用Oracle10g方言:

还要检查一下,确保您使用的是最新的Oracle JDBC驱动程序


谢谢!结果是我覆盖了Spring的applicationContext.xml中的方言:)