Search code examples
playframework-2.0ebean

java - How to do unidirectional one-to-many relationship in Ebean


I have a unidirectional relationship where one entity has a list of another entity (one to many) .

I have set cascade type to CascadeType.ALL, And i am getting error

[PersistenceException: Error inserting bean [class models.User$Activity] with unidirectional relationship. For inserts you must use cascade save on the master bean [class models.User].]

at this line

userForm.get().update(id);

I want to update existing user entry.If i replaced above line by

userForm.get().save();

It creates duplicate entry.Is there any solution.Please help me. My code :

@Valid
@OneToMany(cascade=CascadeType.ALL)
public List<Activity> activities;

Solution

  • I had a lot of trouble with @OneToMany relationships with Ebean. I've also experienced this error message several times. I think you need to have a bidirectional relationship between your entities.