persistence@glassfish.java.net

Recursion

From: Kem Elbrader <kem.elbrader_at_elementline.com>
Date: Tue, 19 Aug 2008 10:12:00 -0600

Suppose we have

@Entity
public class A {

  @Id
  private long id;

  @ManyToOne
  private A parent;

  ... getters and setters

  public List<A> path() {
    List<A> path;
    if (parent != null) {
       path = parent.path();
    } else {
       path = new ArrayList<A>();
    }
    path.add(this);
  }
}

Is it possible to get the list returned by the path method using a EJB query?

Thanks