日期:2014-05-20  浏览次数:20795 次

Hibernate自动生成的sql语句怎么会多了前缀
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_查询出来的数据时正确的,就是多了一个前缀,这怎么解决啊,麻烦高手解答一下,谢谢!

------解决方案--------------------
映射文件,和执行的HQL拿来
------解决方案--------------------
你的映射文件里指定了,不信你去看。
------解决方案--------------------
探讨
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_.na……

------解决方案--------------------
探讨
引用:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not load an entity: [com.oristand.nitpro.entity.Users#9]; bad SQL grammar

[select users0_.userId a……

------解决方案--------------------
catalog="jbpm"去掉
------解决方案--------------------
探讨

catalog="jbpm"去掉

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

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

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

------解决方案--------------------
catalog="jbpm" 这在hibernate里是类似数据库schema的概念

你如果每次都是指明了数据库的HQL操作,这个配置就没什么作用了,去掉即可