File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Transaction comit problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Transaction comit problem" Watch "Transaction comit problem" New topic

Transaction comit problem

Gaurav Chawla

Joined: Jun 23, 2010
Posts: 1
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....
I agree. Here's the link:
subject: Transaction comit problem
It's not a secret anymore!