I may be right or wrong - would have to test it on my own, but its not worth 2$, so Ill just try to post the raw one. You can reward me if I was correct / helped:)
select [login to view URL], [login to view URL], [login to view URL], [login to view URL] from category c left join [login to view URL] as c1 left join [login to view URL] as c2 left join [login to view URL] as c3 where [login to view URL] is null order by [login to view URL], [login to view URL], [login to view URL], [login to view URL];
then your Entity objects should be as follows:
(draft):
@Entity
public class Category {
...
@ManyToOne
@JoinColumn(name="parentid", nullable=true)
private Category parent;
@OneToMany(mappedBy="parent")
private List<Category> children;
private String name;
...
}