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 Martín Capriotti APTIX <mc...@aptix.net> on 2003/09/25 17:01:45 UTC

problem with n:m collection

Hi
I have problems with n:m mappings, it is deleting the referenced objets instead of deleting only the reference (when I delete it from the collection)
(behaving as if  auto-delete="true" is set)


Example:
one way n:m direct mapping from Roles to Usuario (nothing mapped from Usuario to Rol)

-------------------- MAPPING OF COLLECTION usuarios IN CLASS Rol ----------------------------------
<class-descriptor ... Rol...>
...
<collection-descriptor
 name="usuarios"
 element-class-ref="net.aptix.intranet.seguridad.Usuario"
 indirection-table="ROLES_USR" >
   <fk-pointing-to-this-class column="ID_ROL"/>
   <fk-pointing-to-element-class column="ID_USR"/>

</collection-descriptor> 

-------------class Rol----------------------


.....

public Collection usuarios = new Vector();

.....

public Collection getUsuarios() {

return usuarios;

}

public void setUsuarios(Collection _usuarios){

this.usuarios=_usuarios;

}

-----------------------------------

This example should remove one Usuario (id=5) from a Rol (id=10):

Rol r=Rol.getRolById(10);

Usuario u= Usuario.getUsuariobyId(5);

r.getUsuarios.remove(u);

store...

----------------------------------------------------------------------

It does the work.. and more: It removes Usuario "u" from the collection as it should, but it also removes that object Usuario (id=5) from DB, as if  auto-delete="true" has been set!

It seems this problem started when we moved from OJB 0.97 to 1RC4

Thanks , Martín.



Re: problem with n:m collection

Posted by Martín Capriotti APTIX <mc...@aptix.net>.
It worked out setting the collection-class to ManageableVector


Thank you all.


----- Original Message ----- 
From: "sclark" <sc...@euler.cr.usgs.gov>
To: <oj...@db.apache.org>
Sent: Thursday, September 25, 2003 12:08 PM
Subject: Re: problem with n:m collection


> This is because the default behavior was recently changed; collections now
use
> RemovalAwareCollection by default, which has the effect of deleting the
> contained object as well as the relationship.  The fix is to specify a
different
> ManageableCollection implementation in the collection-class attribute of
your
> collection-descriptor.
>
> Because this surprising and fundamental change in behavior has been made
at such
> a late date (RC3 or 4?), it seems that it should be noted in the release
notes
> and perhaps added to the FAQ.
>
> -steve
>
> Steve Clark
> Technology Applications Team
> Natural Resources Research Center/USGS
> sclark@detox.cr.usgs.gov
> (970)226-9291


----- Original Message ----- 
From: "Réda Benzair" <re...@smartjog.com>
To: "'OJB Users List'" <oj...@db.apache.org>
Sent: Thursday, September 25, 2003 12:34 PM
Subject: RE: problem with n:m collection


> Hi
> can be it is a solution with you to see
> Add in Class-descriptor
> collection-class="org.apache.ojb.broker.util.collections.ManageableVecto
> r"
>
>
> -----Original Message-----
> From: Martín Capriotti APTIX [mailto:mcaprio@aptix.net]
> Sent: jeudi 25 septembre 2003 17:02
> To: ojb-user@db.apache.org
> Subject: problem with n:m collection
>
> Hi
> I have problems with n:m mappings, it is deleting the referenced objets
> instead of deleting only the reference (when I delete it from the
> collection)
> (behaving as if  auto-delete="true" is set)
>
>
> Example:
> one way n:m direct mapping from Roles to Usuario (nothing mapped from
> Usuario to Rol)
>
> -------------------- MAPPING OF COLLECTION usuarios IN CLASS Rol
> ----------------------------------
> <class-descriptor ... Rol...>
> ...
> <collection-descriptor
>  name="usuarios"
>  element-class-ref="net.aptix.intranet.seguridad.Usuario"
>  indirection-table="ROLES_USR" >
>    <fk-pointing-to-this-class column="ID_ROL"/>
>    <fk-pointing-to-element-class column="ID_USR"/>
>
> </collection-descriptor>
>
> -------------class Rol----------------------
>
>
> .....
>
> public Collection usuarios = new Vector();
>
> .....
>
> public Collection getUsuarios() {
>
> return usuarios;
>
> }
>
> public void setUsuarios(Collection _usuarios){
>
> this.usuarios=_usuarios;
>
> }
>
> -----------------------------------
>
> This example should remove one Usuario (id=5) from a Rol (id=10):
>
> Rol r=Rol.getRolById(10);
>
> Usuario u= Usuario.getUsuariobyId(5);
>
> r.getUsuarios.remove(u);
>
> store...
>
> ----------------------------------------------------------------------
>
> It does the work.. and more: It removes Usuario "u" from the collection
> as it should, but it also removes that object Usuario (id=5) from DB, as
> if  auto-delete="true" has been set!
>
> It seems this problem started when we moved from OJB 0.97 to 1RC4
>
> Thanks , Martín.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


RE: problem with n:m collection

Posted by Réda Benzair <re...@smartjog.com>.
Hi 
can be it is a solution with you to see
Add in Class-descriptor 
collection-class="org.apache.ojb.broker.util.collections.ManageableVecto
r"


-----Original Message-----
From: Martín Capriotti APTIX [mailto:mcaprio@aptix.net] 
Sent: jeudi 25 septembre 2003 17:02
To: ojb-user@db.apache.org
Subject: problem with n:m collection

Hi
I have problems with n:m mappings, it is deleting the referenced objets
instead of deleting only the reference (when I delete it from the
collection)
(behaving as if  auto-delete="true" is set)


Example:
one way n:m direct mapping from Roles to Usuario (nothing mapped from
Usuario to Rol)

-------------------- MAPPING OF COLLECTION usuarios IN CLASS Rol
----------------------------------
<class-descriptor ... Rol...>
...
<collection-descriptor
 name="usuarios"
 element-class-ref="net.aptix.intranet.seguridad.Usuario"
 indirection-table="ROLES_USR" >
   <fk-pointing-to-this-class column="ID_ROL"/>
   <fk-pointing-to-element-class column="ID_USR"/>

</collection-descriptor> 

-------------class Rol----------------------


.....

public Collection usuarios = new Vector();

.....

public Collection getUsuarios() {

return usuarios;

}

public void setUsuarios(Collection _usuarios){

this.usuarios=_usuarios;

}

-----------------------------------

This example should remove one Usuario (id=5) from a Rol (id=10):

Rol r=Rol.getRolById(10);

Usuario u= Usuario.getUsuariobyId(5);

r.getUsuarios.remove(u);

store...

----------------------------------------------------------------------

It does the work.. and more: It removes Usuario "u" from the collection
as it should, but it also removes that object Usuario (id=5) from DB, as
if  auto-delete="true" has been set!

It seems this problem started when we moved from OJB 0.97 to 1RC4

Thanks , Martín.




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org