persistence@glassfish.java.net

many-to-many self-reference

From: Greg Ederer <greg_at_ergonosis.com>
Date: Thu, 06 Sep 2007 11:44:27 -0700

Hi,

I have a Category class. According to my model, a Category can have many
parent Categorys and many child Categorys. I'm having trouble getting
the JPA annotations right for this relationship. I'm sure that this must
be trivially easy.

The source might something look like:

@Entity
public class Category
{
  @Id
  private Long id;
 
  protected String name;
 
  @???
  protected List<Category> parentCategories = new ArrayList<Category>();
 
  @???
  protected List<Category> childCategories = new ArrayList<Category>();
 
  ...
}

What is the correct way to do this?

Thanks!

Greg

-- 
| E R G O N O S I S
| Greg Ederer
| Lead Developer
| greg_at_ergonosis.com
| 360.774.6848
|