gpt4 book ai didi

java - Hibernate + Oracle,原始类型违反奇怪的空约束

转载 作者:行者123 更新时间:2023-12-03 18:07:01 24 4
gpt4 key购买 nike

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

该实体以前是:

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 批处理、读取文件、插入新实体条目以及更新现有条目。

它在本地和开发服务器中工作正常,但在验证服务器中,我在新实体处理(插入)期间遇到此错误

BATCH 03/05/2011 06:41:11 WARN [JDBCExceptionReporter.java:77] - SQL Error: 1400, SQLState: 23000 BATCH 03/05/2011 06:41:11 ERROR [JDBCExceptionReporter.java:78] - ORA-01400: cannot insert NULL into ("mydb"."mytable"."PUBLISHED_DAYS_SINCE_LAST_PUB")

BATCH 03/05/2011 06:41:11 ERROR [AbstractFlushingEventListener.java:301] - Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: could not insert: [com.xxx.myentity] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2262) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2655) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:60) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1001) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:339) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635) at com.xxx.eplatform.websites.webstore.batch.processor.DistrinetDataProcessor$$EnhancerByCGLIB$$42d43018.processDistrinetLine() at com.xxx.eplatform.websites.webstore.batch.services.impl.WebstoreImporterServiceImpl.importDistrinetFile(WebstoreImporterServiceImpl.java:71) at com.xxx.eplatform.websites.webstore.batch.WebstoreImportBatch.execute(WebstoreImportBatch.java:142) at com.xxx.eplatform.websites.webstore.batch.WebstoreImportBatch.main(WebstoreImportBatch.java:104) Caused by: java.sql.SQLException: ORA-01400: cannot insert NULL into ("mydb"."mytable"."PUBLISHED_DAYS_SINCE_LAST_PUB")

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216) at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:966) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1170) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339) at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3423) at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2242) ... 21 more

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

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

有人吗?谢谢

最佳答案

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

关于java - Hibernate + Oracle,原始类型违反奇怪的空约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5872871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com