Hi,

We're using a combination of H2 with JPA and Hibernate to run
integration tests for our project. We're running the tests in
compatiabilty mode with MODE=Oracle.

We're hitting a problem when we try to to update an entity that has
one to many association with a child entity. We have an It System
class that is defined as follows (shortened):
@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<ItsystemAka> itSystemAkas;

       .....
}

The corresponding IT System Aka class (again shortened) is as
follows):
@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;

        ....
}

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, we can see that the
foregin key (IT_SYSTEM_EDW_ID) for the corresponding rows in the
ITSYSTEM_AKA table are getting set to null.

Our connection properties are as follows:
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

I've tried using the Oracle Dialect instead of the native H2 Dialect
as advised in the pdf, but it produces the same result.

Any ideas as to what is going wrong?

Any help would be much appreciated.

Regards,

Priyesh

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to