Hi,
I have a HSQLDB (version 1.8) with 3 tables (Spiel, Satz, Zug).
There are one-to-many-relations between Spiel and Satz and between Satz and Zug.
The database works fine with Hibernate (version 3.1) except for one problem.
In a normal execution of the main programm, one Spiel-object is created, then a Satz-object which is related to the Spiel-object, and then some Zug-objects that are related to this Satz-object.
This works fine as long as I try to only save one Satz-object.
When I try to create a second Satz-object, I get:
Code:
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at vierGewinnt.database.DAO.speichereSatz(DAO.java:250)
at vierGewinnt.database.DAO.main(DAO.java:101)
Zug-, and Spiel-objects can be saved without any problems, but everytime I try to save a 2nd Satz-object, this error occurs.
The mapping file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="vierGewinnt.database.Satz" table="SATZ">
<id name="satzId" column="satzId" type="long">
<generator class="increment" />
</id>
<property name="satzNr" type="long"/>
<property name="sieger" />
<many-to-one name="spiel" class="vierGewinnt.database.Spiel"
column="spielID" />
<set name="zuege" table="ZUEGE" lazy="false">
<key column="satzId" />
<one-to-many class="vierGewinnt.database.Zug" />
</set>
</class>
</hibernate-mapping>
Satz.java
Code:
package vierGewinnt.database;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
public class Satz implements Serializable
{
private Long satzId;
private Long satzNr;
private int sieger;
private Spiel spiel;
private Set zuege ;
public Satz() {
zuege = new HashSet();
}
Getters and Setters
hashCode() and equals()
}
part of the DAO.java
Code:
public void speichereSatz(Long spielId, Long satznr, int sieger)
{
//Satzdaten speichern
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Satz satz = null;
Spiel spiel = null;
Transaction tx = null;
try {
tx = session.beginTransaction();
spiel = (Spiel)session.createCriteria(Spiel.class)
.add(Restrictions.eq("spielId",spielId))
.uniqueResult();
satz = new Satz();
satz.setSpiel(spiel); //Beziehung zum Spiel setzen
satz.setSatzNr(satznr);
satz.setSieger(sieger);
session.save(satz);
tx.commit();
} catch (HibernateException e) {
if (tx!=null) tx.rollback();
System.out.println("Fehler beim Speichern des Satzes");
}
}
Any ideas?
Thanks in advance...
Greetings from Germany,
JBond