原创

迷之bug —— Hibernate command denied to user 'xxx'@'xxx' for table 'xxxx'

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'xxxx'@'xxxxx' for table 'xxxxx' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.6.0_43] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[?:1.6.0_43] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[?:1.6.0_43] at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[?:1.6.0_43] at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2825) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156) ~[mysql-connector-java-5.1.28-bin.jar:?] at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2313) ~[mysql-connector-java-5.1.28-bin.jar:?] at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92) ~[commons-dbcp.jar:1.2.1] at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) ~[hibernate-3.2.6.jar:3.2.6.ga] at org.hibernate.loader.Loader.getResultSet(Loader.java:1787) ~[hibernate-3.2.6.jar:3.2.6.ga] at org.hibernate.loader.Loader.doQuery(Loader.java:674) ~[hibernate-3.2.6.jar:3.2.6.ga] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) ~[hibernate-3.2.6.jar:3.2.6.ga] at org.hibernate.loader.Loader.doList(Loader.java:2213) ~[hibernate-3.2.6.jar:3.2.6.ga] ... 67 more

 

发现问题百度了下,发现很多人说是权限问题,于是乎检查下授权发现授权是正常的,(如果你真的是用户对表没有授权的话,请检查下授权)奇葩的问题来了,项目有正式环境、测试环境、和我本地环境,测试环境和我本地的环境都是正常的,唯独到正式环境就不行了。。。在此陷入迷之bug中。

没办法错误还是得解决,于是乎处于崩溃的边缘,一直找不到问题, 后来无意中看到配置中的一个属性

<?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.xxx.xxx.xxx" table="xxxx" catalog="test">  这个地方写死的设置的是我本地的数据库名称,看到这种想到正式环境不是这个名称,对比了下其他的文件,发现没有这个;

 <id name="id" type="integer">

 <column name="ID" /> 

 <generator class="native" />

 </id>


注 通过eclipse生成的Hibernate.xml会自带(catalog)属性,去掉那个属性后 就可以正常的 crud了,只能说hibernate的提示太坑爹了[泪] 困扰了好几天


正文到此结束
Loading...