我使用HSQLDB和Hibernate。我必須在數據庫級別實現一些功能(觸發...),因此我必須執行一些本地SQL。我創建一個新表(工作),然後嘗試插入一些數據(失敗)。我這樣做是因爲SA不應該違反訪問權限。有人可以猜測爲什麼user lacks privilege or object not found: A492Interface
被拋出?使用原生SQL創建表適用於Hibernate/HSQLDB,插入失敗。爲什麼?
這是我的代碼(簡化):
session.createSQLQuery("CREATE TABLE entity_table_map (entity_name VARCHAR(50) NOT NULL PRIMARY KEY,table_name VARCHAR(50) NOT NULL)").executeUpdate();
session.createSQLQuery("INSERT INTO entity_table_map (entity_name,table_name) VALUES (\"A429Interface\",\"interface\")").executeUpdate();
下面是相關日誌:
[[email protected]]: 0:SQLCLI:SQLPREPARE CREATE TABLE entity_table_map (entity_name VARCHAR(50) NOT NULL PRIMARY KEY,table_name VARCHAR(50) NOT NULL)
[[email protected]]: 0:SQLCLI:SQLEXECUTE:5
[[email protected]]: 0:SQLCLI:SQLFREESTMT:5
[[email protected]]: 0:HSQLCLI:GETSESSIONATTR
[[email protected]]: 0:SQLCLI:SQLPREPARE INSERT INTO entity_table_map (entity_name,table_name) VALUES ("A492Interface","interface")
[[email protected]]: [Thread[HSQLDB Connection @13adc56,5,HSQLDB Connections @19616c7]]: 0:disconnected SA
而且這裏的例外:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:219)
at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1310)
at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:396)
at version.api.VersionAPI.setupDatabase(VersionAPI.java:38)
at test.ui.VersionUI.setupDatabase(VersionUI.java:107)
at test.SetupDatabase.main(SetupDatabase.java:9)
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: A492Interface
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:202)
... 5 more
更新:看來我無法執行任何插入語句。如果我嘗試將數據插入到其他表中,則也會失敗。我一定在做一些真正的愚蠢......但沒有看到它......
'...用戶缺少特權...'您有權限插入此表嗎? –