This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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

Win a copy of Head First Android this week in the Android forum!
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
jQuery in Action, 3rd edition