You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Roland Carlsson <ma...@javalia.se> on 2003/08/03 11:35:52 UTC
delete on indirection-table
Hi!
I have a problem with deleteing relations hold in an indirection-table for an mxn relation. The problem is that it not only deletes the affected row in the indirection-table but also the row in the n-table. So when delete a relation I remove every relation that comes from that n-table row. How do I keep the row in the n-table and only remove the supposed row in the indirection-table.
My repostitory looks like this:
<class-descriptor
class="se.javalia.picture.Picture"
table="PICTURE"
>
<field-descriptor id="1"
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor id="2"
name="pictData"
column="PICTDATA"
jdbc-type="LONGVARBINARY"
/>
<collection-descriptor
name="groups"
element-class-ref="se.javalia.picture.PictGroup"
auto-retrieve="true"
auto-update="true"
indirection-table="pictjoinpictgroup"
>
<fk-pointing-to-this-class column="pictid"/>
<fk-pointing-to-element-class column="groupid"/>
</collection-descriptor>
<class-descriptor
class="se.javalia.picture.PictGroup"
table="PICTGROUP"
>
<field-descriptor id="1"
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor id="2"
name="name"
column="NAME"
jdbc-type="VARCHAR"
/>
<field-descriptor id="3"
name="description"
column="DESCRIPTION"
jdbc-type="VARCHAR"
/>
<!-- FIXME: Load the pictures != lot of memory
<collection-descriptor
name="pictures"
element-class-ref="se.javalia.picture.Picture"
auto-retrieve="true"
auto-update="true"
indirection-table="pictjoinpictgroup"
>
<fk-pointing-to-this-class column="groupid"/>
<fk-pointing-to-element-class column="pictid"/>
</collection-descriptor>
-->
</class-descriptor>
The code in my class:
PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
// Get the pictgroup that should be removed from the picture
Criteria crit = new Criteria();
crit.addEqualTo("id", request.getParameter("groupid"));
Query query = new QueryByCriteria(PictGroup.class, crit);
PictGroup pgr = (PictGroup) broker.getObjectByQuery(query);
// Get the picture to operate on
crit = new Criteria();
crit.addEqualTo("id", request.getParameter("pictid"));
query = new QueryByCriteria(Picture.class, crit);
Picture pict = (Picture) broker.getObjectByQuery(query);
// Remove the pictgroup from the vector
java.util.Vector gr = pict.getGroups();
gr.remove(pgr);
// Store the changes
broker.store(pict);
broker.close();
Thanks in advance
Roland Carlsson