I am completely stuck with retrieving a parent child structure from the database. I cannot create a descent Model that will work with Ebean evolutions because the parent relationship is not recognized by Ebean. What I tried:
public class Category extends Model {
private static final long serialVersionUID = 4660222569406895990L;
private Long id;
private String sfname;
// @ManyToOne -- does not work
// @JoinColumn(name="id")
private Category parent;
public static Finder<Integer, Category> FIND = new Finder<Integer, Category>(Integer.class, Category.class);
}
No matter what I try, the code above is generating the following SQL Evolution script:
create table category (
id bigint,
name varchar(255)
);
And if the above will works, the top level has no parent, so how would or can this work??
I have completely no experience with trees and java, perhaps that why it is so difficult for me :-) Thanks for your help!
** 2013-03-28 EDIT **
As nico
pointed out, I forgot to add @Id
to the primary key. So the, following model, works:
@Id
private Long id;
private String sfname;
@ManyToOne
private Category parent;
You may have forgotten the @Id
annotation under private Long id
:
public class Category extends Model {
private static final long serialVersionUID = 4660222569406895990L;
@Id
private Long id;
...
}