org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not load an entity: [com.oristand.nitpro.entity.Users#9]; bad SQL grammar
 
[select users0_.userId as userId0_, users0_.name as name0_0_, users0_.zhiw as zhiw0_0_ from jbpm__users users0_ where users0_.userId=?]; nested exception is com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'jbpm.jbpm__users' doesn't exist
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'jbpm.jbpm__users' doesn't exist
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)我的表名叫users,生成的语句中的表名却是jbpm_users,我的数据库名叫jbpm,我讲生成的sql语句复制到数据库中去掉jbpm_查询出来的数据时正确的,就是多了一个前缀,这怎么解决啊,麻烦高手解答一下,谢谢! 

解决方案 »

  1.   

    我用SSH写了一个查询方法,后来执行的时候自动打印出来的sql语句多了个前缀,导致查询不到数据,我讲sql复制过去然后去掉多余的前缀再查询诗句是可以查出来的,这是为什么啊
      

  2.   

    映射文件:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="com.oristand.nitpro.entity.Users" table="users" catalog="jbpm">
            <id name="userId" type="java.lang.Integer">
                <column name="userId" />
                <generator class="native" />
            </id>
            <property name="name" type="java.lang.String">
                <column name="name" length="50" not-null="true" />
            </property>
            <property name="zhiw" type="java.lang.String">
                <column name="zhiw" length="50" not-null="true" />
            </property>
        </class>
    </hibernate-mapping>
    Action方法:
      

  3.   

    hibernate把hql编译成sql时会自动加上前缀,如果你选定了执行语句的数据库,在执行带前缀的sql语句肯定会查不到
      

  4.   

    catalog="jbpm" 这在hibernate里是类似数据库schema的概念你如果每次都是指明了数据库的HQL操作,这个配置就没什么作用了,去掉即可
      

  5.   

    <class name="com.oristand.nitpro.entity.Users" table="users" schema="jbpm">
    这样就OK了,
    为什么LZ不反向生成pojo和xml文件呢?