代码
public List findRec(final String hql, final int firstResult,
final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException,
SQLException { Query query = s.createQuery(hql);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
List list = query.list();
return list;
}
});
}public List getRolesCategorys(final int start, final int limit) {
return findRec("from HtSysRolesCategory", start, limit);
}输出的hql:
Hibernate: select htsysroles0_.ROLE_CATE_ID as ROLE1_1_, htsysroles0_.ROLE_CATE_NAME as ROLE2_1_ from HT_SYS.HT_SYS_ROLES_CATEGORY htsysroles0_ limit ?
(怎么多出了limit?  ,我用的是oracle)错误:Struts Problem ReportStruts has detected an unhandled exception:
Messages:     1. ORA-00933: SQL ???????
   2. could not execute query
   3. could not execute query; SQL [select htsysroles0_.ROLE_CATE_ID as ROLE1_1_, htsysroles0_.ROLE_CATE_NAME as ROLE2_1_ from HT_SYS.HT_SYS_ROLES_CATEGORY htsysroles0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute queryFile:  oracle bc/driver/DatabaseError.java
Line number:  112请高手帮忙啊。

解决方案 »

  1.   

    hibernate配置里面的数据库类型配错了。
      

  2.   

    配置文件
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans.xsd
                         http://www.springframework.org/schema/tx
                         http://www.springframework.org/schema/tx/spring-tx.xsd
                         http://www.springframework.org/schema/aop
                         http://www.springframework.org/schema/aop/spring-aop.xsd">
    <!-- apache.dbcp连接池的配置 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">
    </property>
    <property name="url" value="jdbc:oracle:thin:@192.168.1.150:1521:rpms">
    </property>
    <property name="username" value="ht_sys"></property>
    <property name="password" value="ht_sys"></property>
    <!-- 最大活动连接数 -->
    <property name="maxActive" value="100"></property>
    <!-- 最大可空闲连接数 -->
    <property name="maxIdle" value="30"></property>
    <!-- 最大可等待连接数 -->
    <property name="maxWait" value="500"></property>
    <!-- 默认的提交方式(如果不需要事务可以设置成true,在实际应用中一般设置为false,默认为false) -->
    <property name="defaultAutoCommit" value="true"></property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <!-- hibernate方言等相关配置 -->
    <property name="hibernateProperties">
    <props>
    <prop key="connection.useUnicode">true</prop>
    <prop key="connection.characterEncoding">utf-8</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <!-- hbm.xml的映射文件 -->
    <property name="mappingResources">
    <list>
    <value>com/htinfo/htsys/model/HtSysUsers.hbm.xml</value>
    <value>com/htinfo/htsys/model/HtSysRolesCategory.hbm.xml</value>
    </list>
    </property>
    </bean>
    不应该啊,我将query.setMaxResults(maxResults);行代码去掉就没有错误了啊。
      

  3.   

    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>,这是MYSQL的方言吧,改为ORCLE的
      

  4.   

    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>改为org.hibernate.dialect.Oracle9Dialect