-->
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.  [ 10 posts ] 
Author Message
 Post subject: Batch update rowcount error?
PostPosted: Mon Dec 08, 2003 6:14 pm 
Beginner
Beginner

Joined: Sun Sep 21, 2003 12:19 am
Posts: 40
Any idea on this message? I am using MySQL and I didn't specify the batch size.

Thanks.

Some background: I use the Threadlocal pattern where the session is definitely valid and I believe only one thread is doing the update.

12/08/2003 17:11:10 [EROR] HibernatePersistMgrImpl net.sf.hibernate.HibernateException: Batch update row count wrong: 0
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.SessionImpl.executeAll(SessionImpl.java:2306)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2257)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2182)
at com.novarum.nova.persist.HibernatePersistMgrImpl.create


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 7:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try search 'Batch update row count wrong' in the forum.
If nothing work you must give more hints
http://www.hibernate.org/ForumMailinglists/HowToAskForHelp

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 2:37 pm 
Beginner
Beginner

Joined: Sun Sep 21, 2003 12:19 am
Posts: 40
The search is not quite effective since the keywords hit almost every topic. And I was in the rush and hope somebody can give me a quick easy answer if they ever had such problem, so appologize not doing my homework.

Okay, I dug into the hibernate code today when I get more time of course. I found out that it is because I changed id from 'Long' to literal 'long'. The difference is that now the 'long' will be default as 0 and hibernate think it is a saved value and call 'update' instead of 'insert' to mySQL db and of course the SQL is not going to affect anything so the row count return is 0 and hibernate expec the row count return larger than that. After I added 'unsaved-value' in mapping file it works.

In short, whenever you see this message, it means that the SQL generated has been ignored by the DB. Another rule of thumb is always put un-saved value since we need to be more explicit due to primitive instance object always get initialized or maybe Gavin wants to enforce this in the DTD (yeah, I know it is too much, but...).

Thanks for the attention.

epbernard wrote:
Try search 'Batch update row count wrong' in the forum.
If nothing work you must give more hints
http://www.hibernate.org/ForumMailinglists/HowToAskForHelp


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 9:04 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no_ejb wrote:
The search is not quite effective since the keywords hit almost every topic. And I was in the rush and hope somebody can give me a quick easy answer if they ever had such problem, so appologize not doing my homework.


Select the 'Search for all terms' option.

no_ejb wrote:
maybe Gavin wants to enforce this in the DTD

How can you guess you have a primitive type a disallow null unsaved-value in a DTD ?
default unsaved-value=null, I think this is the best default value, and having a default value is definitely good. Whatever, changing that will break previous mapping, so no way.

To you specific problem, setting batch_size=0 should give a more user friendly error.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 11:33 am 
Beginner
Beginner

Joined: Sun Sep 21, 2003 12:19 am
Posts: 40
Quote:
How can you guess you have a primitive type a disallow null unsaved-value in a DTD ?
default unsaved-value=null, I think this is the best default value, and having a default value is definitely good. Whatever, changing that will break previous mapping, so no way.


That is not what I meant, what I meant is unsaved-value should be REQUIRED rather than IMPLIED in DTD.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 11:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no_ejb wrote:
That is not what I meant, what I meant is unsaved-value should be REQUIRED rather than IMPLIED in DTD.

That's why I answered you with the default value stuff.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: net.sf.hibernate.HibernateException: Batch update row count
PostPosted: Fri Feb 25, 2005 6:08 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
Hi,

I read the posts in this thread to solve the exception:

"net.sf.hibernate.HibernateException: Batch update row count wrong: 0"

I havent been able to fix this issue.

I am using hibernate 2. I am using the HibernateSession pattern to get a session.

My mapping file is:
Code:
<?xml version="1.0"?>
   <!DOCTYPE hibernate-mapping PUBLIC
           "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
           "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>

    <class name="med.allegro.sp1.Employee" table="employee">
        <id name="id" unsaved-value="0">
                <generator class="native"/>
        </id>
       
        <map name="benefits" table="employee_benefit" cascade="all">
           <key column="parent_id"/>
           <index column="benefit_name" type="string"/>
           <many-to-many column="benefit_id" class="med.allegro.sp1.Benefit"/>
        </map>
       
         <property name="name" type="string"/>
    </class>
   
    <class name="med.allegro.sp1.Benefit" table="benefit">
      <id name="id" unsaved-value="0">
         <generator class="native"/>
      </id>
      <property name="cost" type="int"/>
   </class>
</hibernate-mapping>


My hibernate.cfg.xml file is:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/test1</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">password</property>
        <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

        <property name="show_sql">true</property>
        <property name="transaction.factory_class">
             net.sf.hibernate.transaction.JDBCTransactionFactory
        </property>
        <property name="hibernate.cache.provider_class">
             net.sf.hibernate.cache.HashtableCacheProvider
        </property>
        <property name="hibernate.hbm2ddl.auto">update</property>

      <!-- c3p0 connection pool settings -->
      <property name="hibernate.c3p0.acquire_increment">3</property>
      <property name="hibernate.c3p0.max_size">15</property>
      <property name="hibernate.c3p0.min_size">3</property>
            
        <mapping resource="med/allegro/sp/SupportProperty.hbm.xml"/>
        <mapping resource="med/allegro/sp1/Employee.hbm.xml"/>
      
    </session-factory>

</hibernate-configuration>


The test java file is:
Code:
/*
* Created on Feb 25, 2005
*/
package med.allegro.sp1;

import java.util.HashMap;
import java.util.Map;

import med.allegro.util.HibernateSession;
import net.sf.hibernate.Session;

public class EmployeeTest
{
    public static void main(String args[])
    {
        try
        {
            Session session = HibernateSession.currentSession();
           
            Employee sp = new Employee();
            Employee sp3 = new Employee();
           
            sp.setName("John Doe");
            Map p = new HashMap();
            p.put("health", new Benefit(200));
            p.put("dental", new Benefit(300));
            sp.setBenefits(p);
           
            sp3.setName("Jim Smith");
            sp3.setBenefits(p);
           
            session.save(sp);
            session.save(sp3);
            session.flush();
           
            Employee sp2 = (Employee)session.load(Employee.class, new Integer(sp.getId()));
           
            Map p2 = sp2.getBenefits();
           
            System.out.println(((Benefit)p2.get("health")).getCost());
            System.out.println(((Benefit)p2.get("dental")).getCost());
           
            session.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}


Here is the complete exception being thrown:
Code:
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:128)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2393)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
   at med.allegro.sp1.EmployeeTest.main(EmployeeTest.java:39)
[/code]


Top
 Profile  
 
 Post subject: Addition to my previous post
PostPosted: Fri Feb 25, 2005 7:02 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
The complete error being thrown is:


Code:
ERROR - Could not synchronize database state with session
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:128)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2393)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
   at med.allegro.sp1.EmployeeTest.main(EmployeeTest.java:37)


Does anyone have an idea as to why this is happening and what I could do to resolve this?


Top
 Profile  
 
 Post subject: This is what i have found so far..
PostPosted: Sat Feb 26, 2005 5:49 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
Hi,

The code below is from the hibernate logs:

Code:
Hibernate: insert into employee (name) values (?)
Hibernate: insert into employee (name) values (?)
Hibernate: update benefit set cost=? where id=?
Hibernate: update benefit set cost=? where id=?
ERROR - Could not synchronize database state with session
net.sf.hibernate.HibernateException: Batch update row count wrong: 0


So the question now is, why is hibernate trying to update the benefit table? Should it not be inserting those records? In the mapping file I have specified un-saved value to be 0 for both the employee and the benefit objects.

Can someone please shed light on this behaviour?


Top
 Profile  
 
 Post subject: Resolved
PostPosted: Sat Feb 26, 2005 5:52 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
Just found out that the constructor for the Benefit table had a major bug. It was initializing the id of the benefit!!. It all works fine now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.