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
|