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]