-->
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 Composite elements foreign key issue
PostPosted: Thu Mar 17, 2005 12:30 pm 
Newbie

Joined: Wed Mar 16, 2005 8:00 pm
Posts: 3
Location: Boise Id
Hibernate version:
Version 2.1
Mapping documents:
<hibernate-mapping package="sp.objects" >
<class name="Role" table="sp_rol">
<id name="roleID" column="rol_id" type="int">
<generator class="native" />
</id>
<property name="name" type="string" length="25">
<meta attribute="use-in-tostring">true</meta>
<column name="name" />
</property>

<property name="description" type="string" length="256" >
<column name="desc"/>
</property>

<property name="updateDate" type="date">
<column name="updt_dt" />
</property>

<property name="updateBy" type="int">
<column name="updt_by" />
</property>
<bag name="permissions" table="sp_rol_permsn" lazy="true">
<key column="rol_id" />
<composite-element class="sp.objects.RolePermission" >
<many-to-one name="screen" class="sp.objects.Screen" >
<column name="scrn_id" />
</many-to-one>
<property name="create" type="string" length="1">
<column name="create" />
</property>
<property name="read" type="string" length="1">
<column name="read" />
</property>
<property name="update" type="string" length="1">
<column name="update" />
</property>
<property name="delete" type="string" length="1">
<column name="delete" />
</property>
<property name="updateDate" type="date" >
<column name="upd_dt" />
</property>
<property name="updateBy" type="int" >
<column name="upd_by" />
</property>
</composite-element>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping package="sp.objects" >
<class name="Screen" table="sp_scrn">
<id name="screenID" column="scrn_id" type="int">
<generator class="native" />
</id>
<property name="name" type="string" length="50">
<meta attribute="use-in-tostring">true</meta>
<column name="name" />
</property>

<property name="updateDate" type="date">
<column name="updt_dt" />
</property>

<property name="updateBy" type="int">
<column name="updt_by" />
</property>

</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
I'm using spring extending HibernateDaoSupport
try {
Screen screen = (Screen) getHibernateTemplate().get(Screen.class, screenID);
Session s = getSession();
if (screen != null) {
s.delete(screen);
}
} catch (Exception e) {
throw new DAOException(e);
}

Hello,

I'm a noob to hibernate, but I'm stoked about it. I've pushed for adoption of it at my work, and for a consoritium project I'm involved with. But I'm having a problem.

When I try to delete a "screen" object, which is referenced by RolePermission composite elements, I can't delete the screen because there are referential contstraints on the table, which is probably the desired effect. So I need to delete the composite elements before I delete the screen. How do I do this?

I have been reading the hibernate documentation, hibernate in action, the forums and faqs, and haven't found the answer to this question.

hope you can help.

Thanks in advance.

Pete


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