在休眠中使用@Column 注释时出现异常

Posted

技术标签:

【中文标题】在休眠中使用@Column 注释时出现异常【英文标题】:I am getting an exception while using @Column annotation in hibernate 【发布时间】:2016-07-10 15:20:38 【问题描述】:

以下是例外:

   SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hibernate: insert into USER_DETAILS (Permanent Address, description, Joined Date, Name, ID) values (?, ?, ?, ?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    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:268)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
    at org.hibernate.tutorial.manjosh.HibernateTest.main(HibernateTest.java:27)
Caused by: java.sql.BatchUpdateException: ORA-00917: missing comma

    at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
    at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10720)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
    ... 8 more
`

【问题讨论】:

你读过这个“ORA-00917:缺少逗号”吗? 【参考方案1】:

请将您的插入更改为

insert into USER_DETAILS ('Permanent Address', 'description', 'Joined Date', 'Name', 'ID') values (?, ?, ?, ?, ?)

【讨论】:

【参考方案2】:

请参考这个post。

您基本上需要转义列名;但是,我建议您避免使用这些类型,这样您就不需要使用此策略。

【讨论】:

以上是关于在休眠中使用@Column 注释时出现异常的主要内容,如果未能解决你的问题,请参考以下文章

@UniqueConstraint 和 @Column(unique = true) 在休眠注释中

Spring MVC“org.hibernate.PropertyAccessException”中的休眠注释映射异常

在 postgresql 中使用休眠注释设置列的默认值

休眠注释:实体没有默认构造函数

TEXT 的休眠列注释

定义映射时出现休眠异常