We've got a tree structure like yours and we use @OneToMany and @ManyToOne

consider this:

class Project {

   //properties.,..

  @OneToMany(mappedBy = "parent")
  private List<Project> relatedProjects;


  @ManyToOne
  private Project parent;

}

but in my point of view if your structure has not more than two levels, in
your case, Project and its related projects and the related projects has no
more related ones then it's much better to have another entity say
RelatedProject and create a one-to-many relationship and avoid using nested
entities.


Håkon Sagehaug wrote:
> 
> Hi
> 
> I want to have some thing like this. Ive got a Project entity, and now i
> want this project to include  a list of other projects, like related
> projects, but struggling a bit how to annotate this and how to design the
> database.
> 
> Some thoughts:
> 
> 1. Create a new entity class that holds a pair of projects, and a list of
> this entity e.g ProjectPair
> 2 Have it mapped, could one us @MapKey(name="project_id") and have a map
> of
> friends projects
> 3. Or as a many-to-many or one-to-many, not sure what is is
> 
> any hints on this?
> 
> cheers, Håkon
> -- 
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/Entity-that-referring-to-it-self-tp2187201p2191099.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to