-->
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.  [ 1 post ] 
Author Message
 Post subject: org.hibernate.jdbc.BatchedTooManyRowsAffectedException
PostPosted: Wed Feb 07, 2007 4:48 pm 
Newbie

Joined: Wed Feb 07, 2007 3:43 pm
Posts: 2
Can someone please help? I've had some code running for sometime and all of a sudden it has stopped working in the sense that I can't update objects. I have a simple table in MS SQL 2000:

PK WebUserID int
PersonID int
UserName nvarchar 50 (unique)
Password nvarchar 50
SecurityLevel int
WebUserTypeID int
DoNotShowMyPicture bit
HasFrontPageWeb bit
Comment varchar 1000
TMStamp datetime 8
DefaultEMailForwarderAttempted smallint
BannerID varchar 10

Mapped to this object

WebUser.java (excluded the getters and setters)
public class WebUser {

private int webUserID;
private int personID;
private String userName;
private String password;
private int securityLevel;
private int WebUserTypeID;
private boolean doNotShowMyPicture;
private boolean hasFrontPageWeb;
private String comment;
private Timestamp tMStamp;
private int defaultEMailForwarderAttempted;
private String bannerID;
}

I'm able to query objects and insert objects. However if I try to update an object I get org.hibernate.jdbc.BatchedTooManyRowsAffectedException. If I manually run the update from Query Analyzer, it works fine? If a query the table for duplicate rows, I don't get any?? So why am I get row count 3, expected 1?

The exception states, actual row count: 3; expected: 1. This is telling me that (I think) that there are 3 rows with the same value for the Primary Key? But the primary key is unique? I'm sure I'm doing something incorrectly, but I've been staring at this for too long and can't figure out what I'm doing wrong.

I query an object by UserName in one session, close the session, open another session, I update columns and issue the update and commit and receive the exception. Any help is greatly appreicated!

Hibernate version: 3.2.2

Mapping documents:
WebUser.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="edu.fullcoll.uportal.portlets.webrequest.model.WebUser" table="WebUser" schema="dbo" catalog="Vegas" lazy="false">
<id name="WebUserID" column="WebUserID">
<generator class="identity" />
</id>
<property name="UserName" column="UserName" update="false"/>
<property name="PersonID" column="PersonID" update="false"/>
<property name="Password" column="Password" length="50" update="false"/>
<property name="SecurityLevel" column="SecurityLevel" update="false"/>
<property name="WebUserTypeID" column="WebUserTypeID" update="false"/>
<property name="DoNotShowMyPicture" column="DoNotShowMyPicture"/>
<property name="HasFrontPageWeb" column="HasFrontPageWeb"/>
<property name="Comment" column="Comment"/>
<property name="TMStamp" column="TMStamp"/>
<property name="DefaultEMailForwarderAttempted" column="DefaultEMailForwarderAttempted"/>
<property name="BannerID" column="BannerID" update="false"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
//passing a detached WebUser object
public void updateFPWebInfoInWebUser(WebUser wu, boolean frontpage) {
Session hSession = null;
Transaction nTransaction = null;
try {
if(wu == null) {
throw new Exception("Web User cannot be updated to null");
}

hSession = HibernateUtil.getVegasSessionFactory().openSession();
nTransaction = hSession.beginTransaction();

wu.setHasFrontPageWeb(frontpage);
hSession.update(wu);
nTransaction.commit();

} catch(Exception e) {
if(nTransaction != null)
nTransaction.rollback();
e.printStackTrace();
} finally {
if(hSession != null)
hSession.close();
HibernateUtil.closeVegasSession();
}
}

Full stack trace of any exception that occurs:
org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 3; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:71)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2399)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2303)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2603)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at edu.fullcoll.uportal.portlets.webrequest.services.WebRequestService.updateFPWebInfoInWebUser(WebRequestService.java:328)
at test.java.WebRequestServiceTest.testUpdateFPWebInfoInWebUser(WebRequestServiceTest.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:246)
at org.codehaus.surefire.battery.JUnitBattery.execute(JUnitBattery.java:220)
at org.codehaus.surefire.Surefire.executeBattery(Surefire.java:204)
at org.codehaus.surefire.Surefire.run(Surefire.java:153)
at org.codehaus.surefire.Surefire.run(Surefire.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.surefire.SurefireBooter.run(SurefireBooter.java:104)
at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:303)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Name and version of the database you are using:
Microsoft SQL Server 2000

The generated SQL (show_sql=true):
Hibernate:
update
Vegas.dbo.WebUser
set
DoNotShowMyPicture=?,
HasFrontPageWeb=?,
Comment=?,
TMStamp=?,
DefaultEMailForwarderAttempted=?
where
WebUserID=?
Debug level Hibernate log excerpt:

Solution:
This was the strangest thing!!!! I've been using the microsoft jdbc drivers for a while (over a year) and never had this problem. I switched my drivers to use the jtds drivers, http://jtds.sourceforge.net, and the application works fine again. Hmmmm!

If I switch back to MS jdbc drivers, it doesn't work!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.