Hibernate列名是保留字的解决方法

在Hibernate框架下,如果要操作的列名是Oracle的保留字,则会报如下的错误。

Exception in thread "main" 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:167)
 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 com.accp.dao.impl.LoggerDaoImpl.addLogger(LoggerDaoImpl.java:21)
 at com.accp.dao.impl.LoggerDaoImpl.main(LoggerDaoImpl.java:29)
Caused by: java.sql.BatchUpdateException:<STRONG><SPAN> <SPAN>ORA-00928: 缺失 SELECT 关键字</SPAN></SPAN></STRONG>

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:629)
 at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9409)
 at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:211)
 at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
 at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
 ... 9 more

解决的办法:在Hibernate配置文件中给关键字列加上[关键字列名]

<column length="500" not-null="true" />

Hibernate 的详细介绍请点这里
Hibernate 的下载地址请点这里

Hibernate 中文手册 PDF

Linux shell 字符串操作(长度,查找,替换)

使用Hibernate实现简单的增、改、删、查操作

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e292f0930123da7728e484b80515b424.html