在阿里云RDS新建库和用户,并分配权限,而且用客户端访问连接成功。但启动应用,并修改连接用户和库地址,报错(信息如下)!
字面意思是用户没有SELECT的权限,但客户端验证不是权限问题。
经多步测试发现应用一直在访问同一个数据库,而且名称相同,一直是“A”,最后找到问题真正原因,原来是这个注解的问题,catalog指定数据库名称,就会一直访问这个数据库名,希望大家引以为介。(catalog用法详见“附录”)
@Entity
@Table(name = "t_activity", catalog = "")
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'huospk_jifen'@'10.151.132.48' for table 't_leitai'
at sun.reflect.GeneratedConstructorAccessor51.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2324)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
附录 注:
Table
Table用来定义entity主表的name,catalog,schema等属性。
元数据属性说明:
name: 表名
catalog: 对应关系数据库中的catalog,如果在entitybean中设置此属性,将在表名前面加上catalog指定的值,注意catalog的值一定是数据库的名称,不然会生成的sql语句回报找不到表的错误。
schema:对应关系数据库中的schema
UniqueConstraints:定义一个UniqueConstraint数组,指定需要建唯一约束的列
@Entity
@Table(name="CUST")
public class Customer { ... }
参照:
JPA注解 catalog
http://blog.csdn.net/yangqicong/article/details/6906284