JPA query for getting the whole tree

Posted by Javi on Stack Overflow See other posts from Stack Overflow or by Javi
Published on 2010-04-08T08:51:45Z Indexed on 2010/04/08 8:53 UTC
Read the original article Hit count: 368

Filed under:
|
|
|

Hello,

I have a class which models all categories and they can be ordered hierarchically.

@Entity
@Table(name="categories")
public class Category {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sequence")
    @SequenceGenerator(name="sequence", sequenceName="categories_pk_seq", allocationSize=1)
    @Column(name="id")
    private Long id;

    @Column
    private String name;

    @OneToOne
    @JoinColumn(name="idfather")
    private Category father;

}

I need to get all categories ordered hierarchically (I mean every father followed by its children and fathers ordered alphabetically on each level) as they could be made for example with PRIOR in oracle. Is it possible to do this with a JPA Query (not a SQL one)?

Thanks.

© Stack Overflow or respective owner

Related posts about jpa

Related posts about persistence