I'm currently creating a ebean model User
which trying to map back to itself. Since the User
and it's child uses the data structure, my idea is to reuse them without creating a new model / table.
@Entity
public class User extends Model {
@Id
private String id;
private String email;
@ManyToOne(cascade = CascadeType.PERSIST)
private User parent;
@ElementCollection(fetch = FetchType.LAZY)
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<User> childs = new ArrayList<>();
....
}
And the database schema looks like this:
CREATE TABLE user (
id CHAR(7),
email CHAR(255),
parent_id CHAR(255),
...
);
The mapping @ManyToOne
from child to parent is working fine. But i get the error below when running the app with the @OneToMany
mapping introduced:
javax.persistence.PersistenceException: Error on models.User.childs Can not find mappedBy property [user] in [models.User]
I suspect ebean was trying to look for user_id
in user
table, which in fact it was linked by parent_id
as screen in the database structure.
Any idea if this even supported by ebean or is there anything i'm missing here?