Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:Hibernate 3.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:MySql
The generated SQL (show_sql=true):yes
Debug level Hibernate log excerpt:
I am using annotation in hibernate and I have a Set in an entity
class User {
....
Set<User> userRoles;
@OneToMany(cascade=CascadeType.PERSIST,targetEntity=Role.class)
@JoinColumn(name="user_id")
@Basic(fetch=FetchType.EAGER)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public Set<Role> getUserRoles() {
return userRoles;
}
}
my problem is when remove an object from userRoles, Hibernate first update the role table to null:
---<console>---
Hibernate: update role set user_id=null where user_id=? and role_name=? and user_id=?
---------------
and then try to delete that object
----<console>----
Hibernate: delete from role where role_name=? and user_id=?
ERROR - BatchingBatcher.doExecuteBatch(61) | Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:145)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
at com.hibertest.test.HiberTest.testRemoveUserRole(HiberTest.java:51)
at com.hibertest.test.HiberTest.main(HiberTest.java:39)
-------------
because it was set to null before, second statement fails. before I solve this by set the inverse="true" in hbm.xml file but dont know how to improve it in annotation.
thanks