Hibernate 與 MySql 資料庫關鍵字衝突You have an error in your SQL syntax; check the manual
誒..說來,實在是慚愧.一個錯誤.害慘我了..搞了幾個小時.. 今天使用JSF+Spring+Hibernate框架 和mysql資料庫做專案時,發生一個異常..
我萬萬沒有想到..居然是關鍵字,所引起的..
具體Hibernate生成的sql語句如下:
Hibernate:
insert
into
pl_roles_acl
(ROLE_NAME, SORT_ORDER, RESOURCE_NAME, READ, CREATE, UPDATE
, DELETE, EXECUTE)
values
(?, ?, ?, ?, ?, ?, ?, ?)
2011-01-05 15:55:27,296 [WARN ] org.hibernate.util.JDBCExceptionReporter - SQL Error: 1064, SQLState: 42000
2011-01-05 15:55:27,296 [ERROR] org.hibernate.util.JDBCExceptionReporter - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'READ, CREATE, UPDATE, DELETE, EXECUTE) values ('SAP', 4, 'userMaintenance', 0, 0' at line 1
2011-01-05 15:55:27,296 [ERROR] org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
做專案的時候, 朋友們, 千萬要避免mysql或者其他資料有關鍵字的問題..
如果有關鍵字 ..
也可以,在所對應的 .XXX.Hibernate.hbm.xml 檔案裡面改 ,具體操作如下:
看紅色的標記,. 在關鍵字中 加 "[]" .或者 加, \" \" 或者 '"READ" '..都行
<!-- 在角色物件中拿到所有的許可權;-->
<list name="acEntry" lazy="false" table="pl_roles_acl" >
<key column="ROLE_NAME" />
<list-index base="0" column="SORT_ORDER"/>
<composite-element class="com.rs.common.core.model.AccessControlEntry" >
<property name="entryName" type="java.lang.String">
<column name="RESOURCE_NAME" sql-type="varchar" not-null="true" />
</property>
<property name="permissionRead" >
<column name="[READ]" not-null="false" />
</property>
<property name="permissionCreate">
<column name="[CREATE]" not-null="false" />
</property>
<property name="permissionModify">
<column name="[UPDATE]" not-null="false" />
</property>
<property name="permissionDelete">
<column name="[DELETE]" not-null="false" />
</property>
<property name="permissionExecute">
<column name="[EXECUTE]" not-null="false" />
</property>
</composite-element>
</list>
相關文章
- 錯誤內容:You have an error in your SQL syntax; check the manual that corresponds to your MySQL serverErrorMySqlServer
- 如何解決"You have an error in your SQL syntax"ErrorSQL
- 萬能方法解決——You have an error in your SQL syntaxErrorSQL
- Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQLMySqlJDBCExceptionError
- 帝國CMS安裝時出現You have an error in your SQL syntax錯誤程式碼的解決方法ErrorSQL
- Git更新本地倉庫及衝突"Commit your changes or stash them before you can merge"解決GitMIT
- git在pull時報錯You have not concluded your mergeGit
- 解決 Git 更新本地衝突:commit your changes or stash them before you can mergeGitMIT
- 資料庫SQL語句中關於explain關鍵字的用法資料庫SQLAI
- mysql database manual(mysql資料庫手冊)MySqlDatabase資料庫
- git-----You have not concluded your merge (MERGE_HEAD exists)解決Git
- MySQL 資料庫與 SQL 優化MySql資料庫優化
- SQL、Mysql、資料庫到底什麼關係MySql資料庫
- 【SQL】13 SQL 別名、SQL 連線(JOIN)、SQL INNER JOIN 關鍵字、SQL LEFT JOIN 關鍵字、SQL RIGHT JOIN 關鍵字、SQL FULL OUTER JSQL
- [20200801]sql hint衝突.txtSQL
- Python+資料庫測試常用關鍵字Python資料庫
- vs code jshint報錯或者Open browser failed!! Please check if you have installed the browser correctly!錯誤.JSAI
- 如何解決邏輯刪除與資料庫唯一約束衝突資料庫
- [20200107]vim 按鍵與金山詞霸衝突.txt
- SQL Server資料庫備份保護的關鍵UMSQLServer資料庫
- MYSQL資料庫------SQL優化MySql資料庫優化
- MySql插入唯一鍵衝突的三種可選方式MySql
- 演算法與資料結構——雜湊衝突演算法資料結構
- openGauss備庫wal-replay與query衝突
- Github Fork倉庫的衝突與同步管理Github
- Do you wish to have better graphics?
- Laravel5.4 資料庫遷移錯誤 SQLSTATE [42000] Syntax error or access violation 1071Laravel資料庫SQLError
- 保留關鍵字 (Transact-SQL)SQL
- mysql 中sql語句關鍵字的書寫順序與執行順序MySql
- PostgreSQL 資料庫中 DISTINCT 關鍵字的 4 種用法SQL資料庫
- windows10玩遊戲鍵盤衝突怎麼辦 win10遊戲與鍵盤衝突解決方法Windows遊戲Win10
- 【資料庫學習】資料庫平臺:mysql,sql server資料庫MySqlServer
- 如何解決"Parse error: syntax error"Error
- mpi4py安裝報錯error: Cannot compile MPI programs. Check your configuration!!!ErrorCompile
- 30000字學完MySql資料庫(安裝、SQL、索引、事務等)MySql資料庫索引
- abstract關鍵字 super 關鍵字 類與繼承繼承
- SQL與NoSQL(關係型與非關係型)資料庫的區別SQL資料庫
- 資料庫報錯java.sql.SQLException: Field ‘id‘ doesn‘t have a default value資料庫JavaSQLException
- 【MySQL】gh-ost改雙主表結構主鍵衝突問題MySql