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: bidirectional many-to-many
PostPosted: Wed Dec 15, 2004 1:07 pm 
Newbie

Joined: Tue Nov 30, 2004 11:39 am
Posts: 4
2.13

Hi,

I am trying to implement soft delete. I am using hibernate 2.13 with mysql, spring and tomcat. I have 2 classes Entity.java and EntityGroup.java. There is a bi-directional many-to-many mapping between Entity and EntityGroup. Entity maps to tbl_entity table and EntityGroup maps to tbl_entity_grp table. Both the tables have a column fld_record_status. When a group or entity is deleted, instead of physically deleting the record, the fld_record_status is set to 'D'.

The mapping files for EntityGroup.java(EntityGroup.hbm.xml) is

<hibernate-mapping
>
<class
name="org.appfuse.model.EntityGroup"
table="tbl_gen_desc"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
where="fld_record_status!='D' "
>

<id
name="genDescID"
column="id_gen_desc"
type="java.lang.Long"
>
<generator class="increment">
</generator>
</id>

<idbag
name="members"
table="tbl_entity_grp"
lazy="false"
cascade="none"
>
<collection-id
column="id"
type="java.lang.Long"
>
<generator class="increment">
</generator>
</collection-id>
<key
column="key_group"
>
</key>

<many-to-many
class="org.appfuse.model.Entity"
column="key_entity"
outer-join="auto"
/>

</idbag>

<property
name="recordStatus"
type="char"
update="true"
insert="true"
access="property"
column="fld_record_status"
not-null="true"
/>


The mapping file for Entity.java(Entity-hbm.xml) is

<class
name="org.appfuse.model.Entity"
table="tbl_entity"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
where="fld_record_status!='D' "
>

<id
name="entityKey"
column="key_entity"
type="java.lang.Long"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Entity.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<idbag
name="groups"
table="tbl_entity_grp"
lazy="false"
cascade="none"
>
<collection-id
column="id"
type="java.lang.Long"
>
<generator class="increment">
</generator>
</collection-id>

<key
column="key_entity"
>
</key>

<many-to-many
class="org.appfuse.model.EntityGroup"
column="key_group"
outer-join="auto"
/>

</idbag>

<property
name="recordStatus"
type="char"
update="true"
insert="true"
access="property"
column="fld_record_status"
not-null="true"
/>


Now when I access an Entity, I want to get a list of groups the entity belongs whose fld_record_status is not set to 'D'.
It looks like I cannot specify a "where" clause for a many-to-many mapping.

The code to obtain an entity is

List e = (List)getHibernateTemplate().find("from Entity e where e.firstName=? and e.lastName=?",new Object[]{sFirstname, sLastname}, new Type[]{Hibernate.STRING, Hibernate.STRING});
Entity entity = (Entity)e.get(0);
return entity

The groups property of entity also has groups which are deleted. Is there a way that I can obtain only those groups whose fld_record_status is not set to 'D'.

I am new to hibernate. Any help will be appreciated.

Thanks,

matetn


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.