These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: RowCountWrong HibernateException
PostPosted: Sun Aug 28, 2005 9:37 am 
Newbie

Joined: Mon May 16, 2005 11:55 am
Posts: 11
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 28, 2005 1:11 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
one potential problem is assigned row identifier with unsaved-value of null.
Try removing the unsaved-value=null in the mapping.

With assigned generator type, the unsaved-value will default to undefined which is more correct.

Code:
<hibernate-mapping>

  <class name="it.unitn.science.crisaune.db.ElMater" table="el_materiali">

    <id name="codice" type="string">
      <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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.