mysql table catalog_hibernate 注解@table( catalog=)作用
在阿里云RDS新建庫和用戶,并分配權(quán)限,而且用客戶端訪問連接成功。但啟動應(yīng)用,并修改連接用戶和庫地址,報錯(信息如下)!
字面意思是用戶沒有SELECT的權(quán)限,但客戶端驗證不是權(quán)限問題。
經(jīng)多步測試發(fā)現(xiàn)應(yīng)用一直在訪問同一個數(shù)據(jù)庫,而且名稱相同,一直是“A”,最后找到問題真正原因,原來是這個注解的問題,catalog指定數(shù)據(jù)庫名稱,就會一直訪問這個數(shù)據(jù)庫名,希望大家引以為介。(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等屬性。
元數(shù)據(jù)屬性說明:
name:?表名
catalog:?對應(yīng)關(guān)系數(shù)據(jù)庫中的catalog,如果在entitybean中設(shè)置此屬性,將在表名前面加上catalog指定的值,注意catalog的值一定是數(shù)據(jù)庫的名稱,不然會生成的sql語句回報找不到表的錯誤。
schema:對應(yīng)關(guān)系數(shù)據(jù)庫中的schema
UniqueConstraints:定義一個UniqueConstraint數(shù)組,指定需要建唯一約束的列
@Entity
@Table(name="CUST")
public?class?Customer?{?...?}
參照:
JPA注解 catalog
http://blog.csdn.net/yangqicong/article/details/6906284
總結(jié)
以上是生活随笔為你收集整理的mysql table catalog_hibernate 注解@table( catalog=)作用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最受玩家追捧显卡、系统一览:CPU上AM
- 下一篇: mysql 导出数据库中的某张数据表_m