openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andiqo <nocquid...@gmail.com>
Subject Re: avoid calling evict?
Date Wed, 27 Aug 2008 13:21:06 GMT

Hi,

Thanks, I really appreciate you took time to answer such a "general"
question!

I try to persist a graph in database and I found your link, Pinaki, really
interesting. My concern is a little bit different as my "main entity" is the
Node (a Node is potentially connected to other Node(s), but not
necessarily).

Here are 2 classes of my domain object (renamed fields: to = target; from =
source):

@Entity
public class Node {
   ...
   @ManyToMany(mappedBy = "target")
   @ElementDependent
   private Set<Edge> sources = new HashSet<Edge>();

   @ManyToMany(mappedBy = "source")
   @ElementDependent
   private Set<Edge> targets = new HashSet<Edge>();
   ...
}

@Entity
public class Edge {
   ...
   @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
   // Manage deletion by code
   private Node source;

   @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
   // Manage deletion by code
   private Node target;

   /** The qualifier of this relationship */
   @Basic(fetch = FetchType.LAZY)
   private int kind;
   ...
}

You're right Graig, I only wish to cascade delete the target Nodes (and not
the 'sources' collection). I thought using the 'kind' attribute in order to
distinguish between cascade delete or not (of course, only one cascaded-link
could reach one Node) but i should rather add a 'cascaded' attribute if I
want the 'kind' to stay the qualifier of the link. 

Perhaps a better option is to only cascade-delete a Node, if there is no
more link pointing to it (taking care not to loop several times over Nodes).
Thus the 'cascaded' attribute would be useless. I have to think about it...

Thanks a lot!

Nicolas
-- 
View this message in context: http://n2.nabble.com/avoid-calling-evict--tp783696p786923.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message