title: Using One-to-Many associations with H2, JPA annotations and Hibernate Problem
body: <p>We're using a combination of H2, JPA annotations, Spring and Hibernate to develop our webapp. We're using H2 in compatiability mode with MODE=Oracle.</p>
  
  <p>We have an ItSystem class that has an one-to-many association with an ItSystemAka class as follows:</p>
  
  <pre><code>@Entity 
  @Table(name="ITSYSTEM") 
  public class ItSystem implements Serializable { 
      private static final long serialVersionUID = 1L; 
      private static final String SEQ_NAME = "SeqName"; 
      private static final String SEQUENCE = "sequence"; 
  
      @Id 
      @GeneratedValue(generator = SEQ_NAME) 
      @GenericGenerator(name = SEQ_NAME,strategy = SEQUENCE, parameters = { @Parameter(name = SEQUENCE, value = "IT_SYSTEM_SEQ") }) 
      @Column(name="ITSYSTEM_EDW_ID") 
      private BigDecimal itSystemEdwId; 
  
      @Column(name="ITSYSTEM_VERSION_ID") 
      private BigDecimal itSystemVersionId; 
  
      @OneToMany(fetch = FetchType.EAGER, cascade={CascadeType.ALL}) 
      @JoinColumn(name="ITSYSTEM_EDW_ID") 
      private Set&lt;ItsystemAka&gt; itSystemAkas; 
  
      ..... 
  }
  
  @Entity 
  @Table(name="ITSYSTEM_AKA") 
  public class ItSystemAka implements Serializable { 
      private static final long serialVersionUID = 1L; 
      private static final String SEQ_NAME = "SeqName"; 
      private static final String SEQUENCE = "sequence"; 
  
      @Id 
      @GeneratedValue(generator = SEQ_NAME) 
      @GenericGenerator(name = SEQ_NAME,strategy = SEQUENCE, parameters = { @Parameter(name = SEQUENCE, value = "IT_SYSTEM_AKA_SEQ") }) 
      @Column(name="AKA_EDW_ID") 
      private BigDecimal akaEdwId; 
  
      private String aka; 
  
      @Column(name="ITSYSTEM_EDW_ID") 
      private BigDecimal itSystemEdwId; 
  
      .... 
  }
  </code></pre>
  
  <p>We're using the following connection properties:</p>
  
  <pre><code>myDataSource.driverClassName=org.h2.Driver 
  myDataSource.url=jdbc:h2:~/test;MODE=Oracle;DB_CLOSE_DELAY=-1 
  myDataSource.username=sa 
  myDataSource.password= 
  sessionFactory.hibernateProperties[hibernate.dialect]=org.hibernate.dialect­.H2Dialect 
  sessionFactory.hibernateProperties[hibernate.hbm2ddl.auto]=create 
  sessionFactory.hibernateProperties[hibernate.show_sql]=false 
  sessionFactory.hibernateProperties[hibernate.connection.autocommit]=false 
  sessionFactory.hibernateProperties[hibernate.format_sql]=true 
  </code></pre>
  
  <p>If we have an instance of ItSystem with a number of ItSystemAka instances and we try and update the ItSystem instance to the database, then it is losing the reference to all the associated ItSystemAkas. Looking at the database with the H2 Console, I can see that the 
  foregin key (IT_SYSTEM_EDW_ID) for the corresponding rows in the 
  ITSYSTEM_AKA table are getting set to null.</p>
  
  <p>I've tried using the Oracle Dialect instead of the native H2 Dialect as advised on the H2 website, but it produces the same results. I've also tried using an actual Oracle database instead of H2, in which case everything seems to work fine.</p>
  
  <p>Any idea as to what is going wrong?</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p>Regards,
  Priyesh</p>