-->
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.  [ 10 posts ] 
Author Message
 Post subject: Meaning of HibernateException: Batch update row count wrong?
PostPosted: Tue Jan 06, 2004 3:45 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Hello everyone,

I don't get the meaning of

net.sf.hibernate.HibernateException: Batch update row count wrong: 0

I get this when specifying a jdbc.batch_size property value greater than 0. (for a value of 0, I get "net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)" instead)

This happens when I commit a transaction with two new objects (one parent, one dependant).

I'm using Hibernate 2.1.1, MySQL 3.23.58 and ConnectorJ 3.0.9.

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 4:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please show your mappings and the code you are executing


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 4:26 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
The data/object model is the User-UserRole relationship that is used by JDBCRealm of Tomcat 4.x:

One User can have multiple Roles, like "user" and "admin".

I have stripped the XDoclet-generated mapping descriptors down to what I think is essential:

<class
name="de.schildbach.user.business.User"
table="users"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="name"
column="user_name"
type="string"
>
<generator class="assigned">
</generator>
</id>

<property
name="password"
type="string"
update="true"
insert="true"
column="user_pass"
/>

<set
name="userRoles"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted"
>

<key
column="user_name"
/>

<one-to-many
class="de.schildbach.user.business.UserRole"
/>
</set>

</class>

<class
name="de.schildbach.user.business.UserRole"
table="user_roles"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="integer"
>
<generator class="identity">
</generator>
</id>

<many-to-one
name="user"
class="de.schildbach.user.business.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="user_name"
not-null="true"
/>

<property
name="roleName"
type="string"
update="true"
insert="true"
column="role_name"
/>

</class>

Here is my code, adapted from manual chapters 9.2 and 9.3:

Session session = HibernateUtil.currentSession();
Transaction tx = null;

try
{
tx = session.beginTransaction();

if(session.find("FROM " + User.class.getName() + " u WHERE u.name = ?", userName, Hibernate.STRING).size() > 0)
throw new ActionException("error_user_exists");

UserRole role = new UserRole();
role.setRoleName("user");

User user = new User();
user.setName(userName);
user.setPassword(password);
// ...set other properties...
user.setUserRoles(new HashSet());
user.addUserRole(role);

session.save(user);

tx.commit(); // this is where the exception is thrown

}
catch(RuntimeException x)
{
if(tx != null) tx.rollback();
throw x;
}
finally
{
HibernateUtil.closeSession();
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 4:29 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
I forgot to post the addUserRole method in User:

public void addUserRole(UserRole role)
{
role.setUser(this);
userRoles.add(role);
}

All normal properties are straightforward, I'll post just the instance variables:

User:

private String name;
private String password;
private Set userRoles;

UserRole:

private int id;
private User user;
private String roleName;


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 4:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just a quick look ... missing an inverse=true for your many-to-one?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 4:41 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
I've got the "inverse" on the side of the collection.

This is in accordance with the example in chapter 9.2.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 4:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Oh yes, sorry, didn't look properly ... let's see if I can find something else


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 4:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably a driver issue, have you tried using the 3.1. MySQL Connector release for a test?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 5:04 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
That reminds me that I am using relaxAutoCommit=true and MyISAM tables. Could this be a problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 5:21 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
A simple replacement of

mysql-connector-java-3.0.9-stable-bin.jar

with

mysql-connector-java-3.1.0-alpha-bin.jar

does not help.

Even the removal of "relaxAutoCommit=true" in the JDBC URL does not prevent the exception.


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

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.