Hi Armin, I'm using PB-api. I understand now that it is the expected behaviour, so I took the advice you gave to Emmanuel and specified the collection-class so that my collection does not get deleted. It is working fine now.
/** * @ojb.collection element-class-ref="com.model.product.ShadowProduct" * collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList " * foreignkey="formNo" */ private Collection shadowProducts = new ManageableArrayList(); Thanks a lot Nga -----Original Message----- From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Wednesday, 5 May 2004 7:06 PM To: OJB Users List Subject: Re: N:M relations problem/question -> unwanted deletions Hi Nga, > When debugging, I noticed that in the method the method "storeCollections" > in PersistenceBrokerImpl.class, cod.getCascadingStore() returns > "CASCADE_LINK" and not "CASCADE_NONE" This is the intended behaviour. To be backward compatible auto-udate 'false' was set to 'CASCADE_LINK', see more http://db.apache.org/ojb/tutorial3.html#1:n%20auto-xxx%20setting You don't specify the used api (PB-api, ODMG-api). If you are using ODMG this behaviour is intended. ODMG-api is not so flexible as the PB-api. If you want to keep the object of a 1:n relation in DB without the FK to main object you have to do it by hand. regards, Armin Nga Duong wrote: > Hi, > > I'm having the same problem except that I have a 1:m relationship. > > /** > * @ojb.collection > element-class-ref="com.model.product.ShadowProduct" > * foreignkey="formNo" > * auto-update="false" > * auto-delete="false" > */ > private Collection shadowProducts = new RemovalAwareCollection(); > > I'm also using db-ojb-1.0.rc6 and even though I explicitly specified > auto-update=false auto-delete=false, the collection is being deleted. > When debugging, I noticed that in the method the method "storeCollections" > in PersistenceBrokerImpl.class, cod.getCascadingStore() returns > "CASCADE_LINK" and not "CASCADE_NONE", hence afterStore is being executed. > > if(cod.getCascadingStore() != CollectionDescriptor.CASCADE_NONE) > { > Object referencedObjects = > cod.getPersistentField().get(obj); > if(cod.isMtoNRelation()) > { > storeAndLinkMtoN(false, obj, cod, referencedObjects, > insert); > } > else > { > storeAndLinkOneToMany(false, obj, cod, > referencedObjects, insert); > } > // invoke callback on collection > if (referencedObjects instanceof ManageableCollection) > { > ((ManageableCollection) > referencedObjects).afterStore(this); > } > } > > I also tried to get the latest source code from CVS and built it. But the > problem remains. Any idea? > > Thanks > > Nga > -----Original Message----- > From: Emmanuel Mascarenas [mailto:[EMAIL PROTECTED] > Sent: Wednesday, 5 May 2004 9:06 AM > To: [EMAIL PROTECTED] > Subject: N:M relations problem/question -> unwanted deletions > > > 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] > > > --------------------------------------------------------------------- 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]