title: Hibernate + Oracle, strange null constraint violation with primitive type
body: <p>I just add a new column on an entity and a strange thing is happening.</p>
  
  <p>The entity was previously:</p>
  
  <pre><code>int publishedDayNb;
  
  
  public int getPublishedDayNb() {
      return publishedDayNb;
  }
  
  public void setPublishedDayNb(int publishedDayNb) {
      this.publishedDayNb = publishedDayNb;
  }
  </code></pre>
  
  <p>And the entity is now:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>As you can see i've just added a column.</p>
  
  <p>The sql script to do that in database was:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>I'm doing a java batch processing, reading a file, inserting new entity entries, and updating existing ones.</p>
  
  <p>It works fine in local and in dev server, but in validation server, i've got this error during a new entity processing (insert)</p>
  
  <blockquote>
    <p>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")</p>
    
    <p>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")</p>
    
    <p>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</p>
  </blockquote>
  
  <p>I don't understand what is wrong since the primitive type i added to the entity is always initialized at 0 so it shouldn't be null.</p>
  
  <p>I've also looked my entity class with javap and it seems it's the right version of the entity: my new attribute is there.</p>
  
  <p>Anyone? Thanks</p>