Beginner |
|
Joined: Mon Jul 25, 2005 12:35 am Posts: 24 Location: Sri Lanka
|
Hi ,
I have following entries in the hbm.xml mapping file.
<hibernate-mapping package="beyondm.alerta.hibernate.persistent">
<class name="SystemUser" table="SystemUsers">
<id name="stringId" column="UserId" length="50"/>
<property name="password" column="Password" length="200" not-null="true" />
<property name="name" column="Name" length="200" />
<property name="status" column="Status" length="10" />
<set name="roles" table="SystemUser_Roles" lazy="false" cascade="delete" >
<key column="UserId"/>
<many-to-many column="RoleId" class="SystemRole"/>
</set>
</class>
<class name="SystemRole" table="SystemRoles">
<id name="stringId" column="RoleId" length="50"/>
<property name="RoleName" length="50"/>
<set name="modules" table="SystemRole_Modules" lazy="false" cascade="delete" >
<key column="RoleId"/>
<many-to-many column="ModuleId" class="SystemUserModule"/>
</set>
</class>
<class name="SystemUserModule" table="SystemUserModules">
<id name="stringId" column="ModuleId" length="50"/>
<property name="ModuleName" length="50" />
</class>
</hibernate-mapping>
SystemUser and SystemRole classes having many-to-many unidirectional relationship and SystemRole and SystemUserModule classes also having many-to-many unidirectional relationship.
MySQL dialect set as hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
Then I try to delete SystemRole Object. It gives following exceptions..
org.hibernate.exception.ConstraintViolationException: could not delete: [beyondm.alerta.hibernate.persistent.SystemRole#testRole]
..........
...........
Caused by: java.sql.SQLException: General error: Cannot delete or update a parent row: a foreign key constraint fails
at org.gjt.mm.mysql.MysqlIO.sendCommand(MysqlIO.java)
at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(MysqlIO.java)
at org.gjt.mm.mysql.Connection.execSQL(Connection.java)
at org.gjt.mm.mysql.PreparedStatement.executeUpdate(PreparedStatement.java)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:104)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.entity.BasicEntityPersister.delete(BasicEntityPersister.java:2069)
Can somebody tell me how to solve this problem?
I really appreciate for any help.
Thank you.
Thilina.
|
|