Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Transaction comit problem

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to hibernate.
Implementing many to many relationship for employee to benefits, following is the code for implementing class.

package many2many;

import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;

public class EmpBenefit {

* @param args
public static void main(String[] args) {

SessionFactory sesfry = new Configuration().configure().buildSessionFactory();
Session session = sesfry.openSession();
Transaction tx = session.beginTransaction();

Employee emp1 = new Employee();
Employee emp2 = new Employee();

HashSet<Benefit> b1 = new HashSet<Benefit>();
b1.add(new Benefit(50));
b1.add(new Benefit(40));

HashSet<Benefit> b2 = new HashSet<Benefit>();
b2.add(new Benefit(150));
b2.add(new Benefit(140));
System.out.println("Step 1");;

System.out.println("Step 2");

System.out.println("Step 2");

System.out.println(" "+tx.isActive());
System.out.println("Step 3"+tx.toString());
System.out.println(" "+tx.isActive());
System.out.println("Step 3");
session.flush(); // problem
System.out.println("Step 4");

}catch(Exception e)


hibernate mapping xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<class name="many2many.Employee" table="Employee_dtl" >
<id name="e_id" column="E_id">
<generator class="hilo"/>
<property column="Name" name="name" type="string"/>
<set name="benefits" table="employee_benefit" cascade="all">
<key column="parent_id"/>
<many-to-many column="benefit_id" class="many2many.Benefit"/>


<class name="many2many.Benefit" table="Benefit4emp">

<id name="b_id" column="B_id">
<generator class="hilo"/>

<property name="cost" column="Cost" type="int"/>




log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Step 1
Step 2
Step 3org.hibernate.transaction.JDBCTransaction@adb1d4
Hibernate: insert into Employee_dtl (Name, E_id) values (?, ?)
Hibernate: insert into Employee_dtl (Name, E_id) values (?, ?)
Hibernate: update Benefit4emp set Cost=? where B_id=?
Hibernate: update Benefit4emp set Cost=? where B_id=?
Hibernate: update Benefit4emp set Cost=? where B_id=?
Hibernate: update Benefit4emp set Cost=? where B_id=?
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(
at org.hibernate.jdbc.AbstractBatcher.executeBatch(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(
at org.hibernate.impl.SessionImpl.flush(
at org.hibernate.impl.SessionImpl.managedFlush(
at org.hibernate.transaction.JDBCTransaction.commit(
at many2many.EmpBenefit.main(

Kindly suggest the possible errror....
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic