sorry I was not aware that you are using the ODMG-api. I setup a test similar to yours. I got the same result. Seems that it has same behaviour as for 1:n relations. But for m:n relations this behaviour is indeed unwanted (only the entry in indirection table should be removed) and needs to be fixed.
(By the way, current ODMG-api implementation needs specific auto-update/delete setting, both have to be false - see repository doc).
regards, Armin
Emmanuel Mascarenas wrote:
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]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
