Hi Armin,
I'm using db-ojb-1.0.rc6 and I change the collection-class as you write,
but it still deteting the object, I'm also change the auto-update and
auto-delete with every possible value (true,fasle,none)
and this not chage the result.
Object code:
/** @ojb.collection
* collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
* element-class-ref="model.security.Role"
* foreignkey="user_id"
* remote-foreignkey="role_id"
* indirection-table="sc_user_role"
* auto-retrieve="true"
* auto-update="true"
*/
protected Collection roles;
public void removeRole(Role role){
roles.remove(role);
}
repository_user.xml
<collection-descriptor
name="rols"
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
element-class-ref="model.security.Role"
indirection-table="sc_user_role"
auto-retrieve="true"
auto-update="true">
<fk-pointing-to-this-class column="user_id"/>
<fk-pointing-to-element-class column="role_id"/>
</collection-descriptor>
the removal code:
try {
Transaction tx = null;
Implementation odmg = Context.getInstance().getODMG();
tx = odmg.newTransaction();
tx.begin();
tx.lock(aUser,Transaction.WRITE);
aUser.removeRole(aRole);
tx.commit();
}catch (Exception ex) {
ex.printStackTrace();
}
Thanks
Emmanuel
> From: Armin Waibel <[EMAIL PROTECTED]>
> Subject: N:M relations problem/question -> unwanted deletions
> Content-Type: text/plain; charset=us-ascii; format=flowed
>
> Hi Emmanuel,
>
> don't use a removal aware collection class in your
> collection-descriptor. Per default OJB use such a collection to detect
> all removed objects from your 1:n collection.
> So try to set
> collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
> in your collection-descriptor.
>
> regards,
> Armin
>
> Emmanuel Mascarenas wrote:
>
> > I have a simple n:m relation:
> >
> > user *..* rol
> >
> > I brake this with a middle table
> >
> > user 1..* user_rol *..1 rol
> >
> > Everything is fine, the problem is when a delete a rol from the rol
> > user's collection, the rol it self is deleted and I want to keep it.
> >
> > Here es the code on user:
> >
> > /** @ojb.collection
> > * element-class-ref="model.security.Rol"
> > * auto-retrieve="true"
> > * auto-update="true"
> > * foreignkey="user_id"
> > * remote-foreignkey="rol_id"
> > * indirection-table="user_rol"
> > */
> > protected Collection roles;
> >
> > Here es the auto generated code on repository_user.xml
> >
> > <collection-descriptor
> > name="roles"
> > element-class-ref="model.security.Rol"
> > indirection-table="user_rol"
> > auto-retrieve="true"
> > auto-update="true"
> >
> > <fk-pointing-to-this-class column="user_id"/>
> > <fk-pointing-to-element-class column="rol_id"/>
> > </collection-descriptor>
> >
> >
> > Thanks all in advance
> > Emmanuel
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>