Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.6
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="it.unitn.science.crisaune.db.ElMater" table="el_materiali">
<id name="codice" type="string" unsaved-value="null">
<column name="codice_mat" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="descrizione" column="descrizione" type="string"/>
<property name="costo" column="costo" type="integer"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():HSession is the factory for Hibernate Sessions, materialiRemoto is the updated collection and materiali is the collection to update.
Code:
public class ElencoMateriali {
private final String firma = "<ElencoMateriali>._ ";
[...]
public String aggiorna() {
try {
materiali = getMateriali();
Session sess = HSessions.currentSession();
Iterator it = materialiRemoto.iterator();
while (it.hasNext()) {
ElMater mat = (ElMater) it.next();
System.out.println(firma+"sess.saveOrUpdate(mat); mat.codice="+mat.getCodice());
sess.saveOrUpdate(mat);
/* EQUIVALENT TO THE FOLLOWING:
if (materiali.contains(mat))
sess.update(mat);
else
sess.save(mat);
*/
}
} catch (HibernateException ex) {
new Exception("impossible to update local collection of ElMater", ex)
.printStackTrace();
}
try {
Session sess = HSessions.currentSession();
sess.flush();
} catch (HibernateException ex) {
new Exception("Error during flushing", ex)
.printStackTrace();
}
return null;
}
}
Full stack trace of any exception that occurs:My std output:
Code:
<HSessions>._ Session s = (Session) session.get();
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=0000
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A001
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A002
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A003
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A004
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A005
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A007
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A008
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A009
<ElencoMateriali>._ sess.saveOrUpdate(mat); mat.codice=A010
<HSessions>._ Session s = (Session) session.get();
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
Hibernate: update el_materiali set descrizione=?, costo=? where codice_mat=?
java.lang.Exception: Error during flushing
at it.unitn.science.crisaune.backing.elmater.ElencoMateriali.aggiorna(ElencoMateriali.java:71)
[...]
Caused by: 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:126)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at it.unitn.science.crisaune.backing.elmater.ElencoMateriali.aggiorna(ElencoMateriali.java:267)
... 48 more
Name and version of the database you are using:
MySql 4.0.20a
The generated SQL (show_sql=true):
included in stdoutput.
Debug level Hibernate log excerpt:
I don't known.