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>  

 

 


你可能感兴趣的:(Hibernate 与 MySql 数据库关键字冲突You have an error in your SQL syntax; check the manual)