我有一个String类型的实体。基础数据类型是VARCHAR(255)。如果我将此数据类型更改为CLOB,则在
期间会出现以下异常entityManager.persist(entity);
这是stacktrace
15:31:43,253 INFO [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl] (EJB default - 4) HHH000010: On release of batch it still contained JDBC statements
15:31:43,268 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 4) SQL Error: -841, SQLState: S0000
15:31:43,268 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 4) Name must start with a letter or '_' and contain letters, digits, or '_'.
15:31:43,268 ERROR [org.hibernate.engine.jdbc.batch.internal.BatchingBatch] (EJB default - 4) HHH000315: Exception executing batch [could not execute batch]
15:31:43,268 WARN [com.arjuna.ats.arjuna] (EJB default - 4) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffff968521df:1920e98e:5641ceff:adc0, org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@ac5829a >: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute batch
...
Caused by: org.hibernate.exception.SQLGrammarException: could not execute batch
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:122)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.doExecuteBatch(BatchingBatch.java:101)
at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.execute(AbstractBatchImpl.java:161)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.executeBatch(JdbcCoordinatorImpl.java:207)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:390)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:303)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:349)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1195)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:109)
... 167 more
Caused by: java.sql.BatchUpdateException: Name must start with a letter or '_' and contain letters, digits, or '_'.
at com.informix.jdbc.IfxPreparedStatement.executeBatch(IfxPreparedStatement.java:3028)
at org.jboss.jca.adapters.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:1077)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:113)
... 177 more
我不知道为什么数据类型会对持久阶段产生影响。你对这里发生的事情有什么暗示吗?如果您需要任何代码,请告诉我。我可能提供的代码太多了。
这是实体
@Entity
@Table(name = "cw_test")
public class CwTest implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="ID")
private Integer id;
// @Column(name = "TEST_COLUMN", columnDefinition="BLOB")
@Column(name = "TEST_COLUMN")
private String testColumn;
public CwTest() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void setTestColumn(String testColumn) {
this.testColumn = testColumn;
}
public String getTestColumn() {
return testColumn;
}
}
这是sql-code
drop table CW_TEST;
create table CW_TEST(ID integer, TEST_COLUMN varchar(255));
drop table CW_TEST;
create table CW_TEST(ID integer, TEST_COLUMN CLOB);
第一部作品,而第二作品没有。
这里输出的是debug-option = true。
11:28:28,797 INFO [stdout] (http-/0.0.0.0:8080-1) Hibernate:
11:28:28,797 INFO [stdout] (http-/0.0.0.0:8080-1) /* insert de.lbank.frep.model.CwTest
11:28:28,797 INFO [stdout] (http-/0.0.0.0:8080-1) */ insert
11:28:28,797 INFO [stdout] (http-/0.0.0.0:8080-1) into
11:28:28,797 INFO [stdout] (http-/0.0.0.0:8080-1) cw_test
11:28:28,797 INFO [stdout] (http-/0.0.0.0:8080-1) (TEST_COLUMN, ID)
11:28:28,797 INFO [stdout] (http-/0.0.0.0:8080-1) values
11:28:28,797 INFO [stdout] (http-/0.0.0.0:8080-1) (?, ?)
11:28:28,829 INFO [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl] (http-/0.0.0.0:8080-1) HHH000010: On release of batch it still contained JDBC statements
11:28:28,829 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-/0.0.0.0:8080-1) SQL Error: -841, SQLState: S0000
11:28:28,829 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-/0.0.0.0:8080-1) Name must start with a letter or '_' and contain letters, digits, or '_'.
11:28:28,829 ERROR [org.hibernate.engine.jdbc.batch.internal.BatchingBatch] (http-/0.0.0.0:8080-1) HHH000315: Exception executing batch [could not execute batch]
11:28:28,829 WARN [com.arjuna.ats.arjuna] (http-/0.0.0.0:8080-1) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffff968521df:496f4a99:565d75bf:55, org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@2c18af11 >: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute batch
这是我的persistence.xml:
<persistence-unit name="persistence_unit" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/INF_APPDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.InformixDialect" />
<property name="hibernate.jdbc.use_streams_for_binary" value="true" />
<property name="hibernate.show_sql" value="${STAGING.hibernate.show_sql:false}" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.jdbc.fetch_size" value="20" />
<property name="hibernate.jdbc.batch_size" value="20" />
<property name="hibernate.jdbc.batch_versioned_data" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.order_updates" value="true" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.id.new_generator_mappings" value="true" />
</properties>
</persistence-unit>
答案 0 :(得分:0)
如果sql语法异常即将到来,您必须检查您的POJO是否映射到您在数据库中创建的任何表。或者你可以使用
<property name="hbm2ddl.auto" value="create"/>
答案 1 :(得分:0)
我认为您在映射文件中使用默认的informix hibernate方言。根据这篇文章(http://www.snailshell.de/blog/archives/2007/06/entry_108.html)和链接的JIRA票证(https://hibernate.atlassian.net/browse/HHH-2646),默认的informix hibernate方言不支持CLOB或BLOB类型。
您是否确认您使用的方言支持此功能?你试过这里链接的自定义方言吗?