Hi,
I'm sorry if this is something very obvious, but I've been trying to insert some data into PostGreSQL using Hibernate and it has not been working so far. I'm using Hibernate 2.1rc1.
I have 2 classes Molecule, Atom
Code:
public class Molecule {
// attributes
private List atoms;
//getter/setter methods
}
public class Atom {
// attributes
//getter/setter methods
}
The association between the two is unidirectional. My mapping documents are as follows:
Code:
<class name="Molecule" table="MOLECULE" discriminator-value="M">
<id name="id" column="molecule_id" type="long">
<generator class="sequence"/>
</id>
<property name="commonName" column="common_name" type="java.lang.String"/>
<property name="molecularFormula" column="molecular_formula" type="java.lang.String" not-null="true"/>
<bag name="atoms" cascade="save-update" lazy="true">
<key column="molecule_id"/>
<one-to-many class="cseo.db.chemical.Atom"/>
</bag>
</class>
<class name="Atom" table="ATOM" discriminator-value="A">
<id name="id" column="atom_id" type="long" unsaved-value="null">
<generator class="sequence"/>
</id>
<property name="atomicNo" column="atomic_number" type="int" not-null="true"/>
<property name="charge" column="charge" type="double" not-null="true"/>
</class>
Now when I try to insert into the database I get the following exception:
Hibernate: select nextval ('hibernate_sequence')
Hibernate: select nextval ('hibernate_sequence')
Hibernate: insert into MOLECULE (common_name, molecular_formula, molecule_id) values (?, ?, ?)
Hibernate: insert into ATOM (atomic_number, charge, atom_id) values (?, ?, ?)
Hibernate: update ATOM set molecule_id=? where atom_id=?
net.sf.hibernate.HibernateException: Batch update row count wrong: 0 at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:55)
at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:105)
at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:537)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2303)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2260)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2182)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
Could anyone please let me know what I am doing wrong? Thanks in advance,
Priya