Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Hibernate 2.0
Mapping documents:
UserPriviledge.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="bean">
<class name="bean.UserPriviledge" table="USER_PRIVILEDGES"
dynamic-update="true">
<id name="userpriviledgeid" column="USERPRIVILEDGE_ID">
<generator class="increment"/>
</id>
<property name="priviledgeid" column="PRIVILEDGE_ID" /> <many-to-one name="userdetail" column="USERDETAIL_ID"
not-null="true" />
</class>
</hibernate-mapping>
UserDetail.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="bean">
<class name="bean.UserDetail" table="USER_DETAILS" dynamic-
update="true">
<id name="userdetailid" column="USERDETAIL_ID">
<generator class="increment" />
</id>
<property name="username" column="USER_NAME" />
<property name="useraddress" column="USER_ADDRESS" />
<property name="deptid" column="DEPT_ID" />
<property name="userage" column="USERAGE" />
<property name="roleid" column="ROLE_ID" />
<property name="modreason" column="MOD_REASON" />
<set name="userpriviledge" inverse="true" lazy="false" order-
by="USERPRIVILEDGE_ID" cascade="all">
<key column="USERDETAIL_ID"/>
<one-to-many class="bean.UserPriviledge"/>
</set>
<many-to-one name="login" column="LOGIN_ID" not-
null="true" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
userDetail.setUserdetailid(Integer.parseInt(userdetailid));
session.update(userDetail.getLogin());
session.update(userDetail);
System.err.println("Before Update. ");
System.err.println("UserPriviledgeId :: "+
userDetail.getUserpriviledgeid().length+ " :: PriviledgeId
= "+ userDetail.getPriviledgeid().length);
if (userDetail.getUserpriviledgeid() != null) {
int arr[] = userDetail.getUserpriviledgeid();
for (int i = arr.length - 1; i >= 0; i--) {
System.err.println("I'th position is :> " + i);
userpriviledge.setUserdetailid(Integer.parseInt
(userdetailid));
userpriviledge.setUserdetail(userDetail);
userpriviledge.setUserpriviledgeid(arr[i]);
session.delete(userpriviledge);
}
}
System.err.println("After Delete.");
Full stack trace of any exception that occurs:
[7/8/05 11:07:20:202 GMT+05:30] e7fef1d WebSphereTran I
net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
WebSphere 5.0
[7/8/05 11:07:20:218 GMT+05:30] e7fef1d SystemErr R Before Update.
[7/8/05 11:07:20:218 GMT+05:30] e7fef1d SystemErr R UserPriviledgeId :: 3 :: PriviledgeId = 2
[7/8/05 11:07:20:218 GMT+05:30] e7fef1d SystemErr R I'th position is :> 2
[7/8/05 11:07:20:234 GMT+05:30] e7fef1d SystemErr R I'th position is :> 1
[7/8/05 11:07:20:234 GMT+05:30] e7fef1d SystemErr R I'th position is :> 0
[7/8/05 11:07:20:234 GMT+05:30] e7fef1d SystemErr R After Delete.
[7/8/05 11:07:20:234 GMT+05:30] e7fef1d SystemErr R Exception is
(in Update) :> net.sf.hibernate.HibernateException: identifier of an
instance of bean.UserPriviledge altered from 1 to 3
[7/8/05 11:07:20:234 GMT+05:30] e7fef1d Configuration I net.sf.hibernate.cfg.Configuration configuring from file: hibernate.cfg.xml
[7/8/05 11:07:20:249 GMT+05:30] e7fef1d Configuration I net.sf.hibernate.cfg.Configuration Mapping resource: hello/UsageBean.hbm.xml
Name and version of the database you are using: ORACLE 8i .
The generated SQL (show_sql=true):
No Sql is generated, because of Exception.
Debug level Hibernate log excerpt: