Hibernate+Oracle,与基元类型有奇怪的null约束冲突



我刚在一个实体上添加了一个新列,就发生了一件奇怪的事情。

该实体以前是:

int publishedDayNb;

public int getPublishedDayNb() {
return publishedDayNb;
}
public void setPublishedDayNb(int publishedDayNb) {
this.publishedDayNb = publishedDayNb;
}

现在的实体是:

int publishedDayNb;
int publishedDayNbSinceLastPublication;

public int getPublishedDayNb() {
return publishedDayNb;
}
public void setPublishedDayNb(int publishedDayNb) {
this.publishedDayNb = publishedDayNb;
}
@Column(name="published_days_since_last_pub")
public int getPublishedDayNbSinceLastPublication() {
return publishedDayNbSinceLastPublication;
}
public void setPublishedDayNbSinceLastPublication(int publishedDayNbSinceLastPublication) {
this.publishedDayNbSinceLastPublication = publishedDayNbSinceLastPublication;
}

正如你所看到的,我刚刚添加了一个专栏。

在数据库中执行此操作的sql脚本是:

alter table mytable add published_days_since_last_pub number(10,0);
update mytable set published_days_since_last_pub=0;
alter table mytable modify published_days_since_last_pub number(10,0) not null;

我正在进行java批处理,读取文件,插入新的实体条目,并更新现有条目。

它在本地和开发服务器中运行良好,但在验证服务器中,我在新实体处理(插入)时遇到了这个错误

批次03/05/2011 06:41:11警告[JDBCExceptionReporter.java:77]-SQL错误:1400,SQL状态:23000批次2011年5月3日06:41:11错误[JDBCExceptionReporter.java:78]-ORA-01400:无法将NULL插入("mydb"、"mytable"、"PUBLISHED_DAYS_SINCE_LAST_PUB")

批次03/05/2011 06:41:11错误[AbstractFlushingEventListener.java:301]-无法将数据库状态与会话同步org.hubinate.exception.ConstraintViolationException:无法插入:[com.xxx.myentity]在org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)在org.hibernate。persister.entity.AbstractEntityPersister.insert(AbstractEntityPersester.java:2262)在org.hibernate。persister.entity.AbstractEntityPersister.insert(AbstractEntityPersester.java:2655)在org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:60)在org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)在org.hibernate。engine.ActionQueue.executeActions(ActionQueue.java:263)在org.hibernate。engine.ActionQueue.executeActions(ActionQueue.java:167)在org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFluidEventListener.java:298)在org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEvent Listener.java:27)在org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1001)在org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:339)在org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)在org.springframework.om.hibernate3.Hibernate TransactionManager.doCommit(Hibernate TransactionManager.java:655)在org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(抽象平台事务管理器.java:732)在org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(抽象平台事务管理器.java:701)在org.springframework.transaction.intercept.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)在org.springframework.transaction.interceptor.TransactionInterceptor.ininvoke(TransactionInterceptor.java:116)在org.springframework.aop.framework.ReflectiveMethodInvocation.prough(ReflectiveMethodInvocation.java:171)在org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.cintercept(Cglib2aop:635)在com.xxx.eplatform.webstore.batch.processer.DistrinetDataProcessor$$EnhancerByCGLIB$$42d43018.processDistrinetLine()com.xxx.eplatform.webstore.batch.services.impl.WebstoreImporterServiceImpl.importDistrinetFile(WebstoreImporter ServiceImpl.java:71)在com.xxx.eplatform.webstore.batch.WebstoreImportBatch.execute(WebstoreImportBatch.java:142)在com.xxx.eplatform.webstore.batch.WebstoreImportBatch.main(WebstoreImportBatch.java:104)由以下原因引起:java.sql.SQLException:ORA-01400:无法将NULL插入("mydb"、"mytable"、"PUBLISHED_DAYS_SINCE_LAST_PUB")

在oracle.jdbc.driver.DatabaseError.sthrowSqlException(DatabaseError.java:112)在oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIeor.java:331)在oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)在oracle.jdbc.driver.T4C8Oall.remove(T4C8Oall.java:745)在oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreperedStatement.java:216)在oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreperedStatement.java:966)在oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1170)在oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedSStatement.java:3339)在oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedSStatement.java:3423)在org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)在org.hibernate。persister.entity.AbstractEntityPersister.insert(AbstractEntityPersester.java:2242)…还有21个

我不明白出了什么问题,因为我添加到实体中的基元类型总是初始化为0,所以它不应该为null。

我还用javap查看了我的实体类,它似乎是实体的正确版本:我的新属性就在那里。

有人吗?感谢

只需将int更改为Integer,看看它是否有助于

相关内容

  • 没有找到相关文章

最新更新