Hibernate 与 MySql 数据库关键字冲突You have an error in your SQL syntax; check the manual

hibernate 使用mysql关键字的配置

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" '..都行

 

Xml代码 复制代码  收藏代码
  1. <SPAN style="COLOR: #888888"><!-- 在角色对象中拿到所有的权限;-->  
  2.         <list name="acEntry" lazy="false" table="pl_roles_acl" >  
  3.             <key column="ROLE_NAME" />  
  4.             <list-index base="0" column="SORT_ORDER"/>  
  5.             <composite-element class="com.rs.common.core.model.AccessControlEntry" >  
  6.                             <property name="entryName" type="java.lang.String">  
  7.                     <column name="RESOURCE_NAME" sql-type="varchar" not-null="true" />  
  8.                 </property>      
  9.                 <property name="permissionRead" >  
  10.                     <SPAN><column name="[READ]" not-null="false" /></SPAN>  
  11.                 </property>  
  12.                 <property name="permissionCreate">  
  13.                     <SPAN><column name="[CREATE]" not-null="false" /></SPAN>  
  14.                 </property>  
  15.                 <property name="permissionModify">  
  16.                     <SPAN><column name="[UPDATE]" not-null="false" /></SPAN>  
  17.                 </property>  
  18.                 <property name="permissionDelete">  
  19.                     <SPAN><column name="[DELETE]" not-null="false" /></SPAN>  
  20.                 </property>  
  21.                 <property name="permissionExecute">  
  22.                     <SPAN><column name="[EXECUTE]" not-null="false" /></SPAN>  
  23.                 </property>  
  24.             </composite-element>  
  25.         </list></SPAN>  

 

 


引用:错误代码: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 'Continue at line 1。用:you have an error in your sql syntax; check the manual that corresponds to y。引用:Query : select * from order LIMIT 0, 1000 Error Code : 1064 You have an error in your SQLsyntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order LIMIT 0, 1000' at line 1。 这些引用内容显示了SQL语法错误和错误代码。当你在使用MySQL服务器时,如果你的SQL语句的语法不正确,就会显示这样的错误消息,指出在SQL语句中的哪一行出现了错误。 要解决这个问题,你应该仔细检查你的SQL语句,并确保它们符合MySQL服务器的语法规定。你可以参考MySQL服务器的官方文档,在其中找到正确的语法和用法。另外,你还可以通过查看错误消息中指定的行号,找到具体出错的位置,然后进行修正。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [You have an error in your SQL syntax... check the manual that corresponds to your MySQL server version](https://blog.csdn.net/Continue_Python/article/details/124320879)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Mysql运行sql文件错误You have an error in your SQL syntaxcheck the manual that corresponds to y](https://blog.csdn.net/yetaodiao/article/details/126562096)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值