-->
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: Deleting problem with many-to-many unidirectional associatio
PostPosted: Tue Aug 23, 2005 9:17 am 
Beginner
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.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.