Reputation: 1
I have a Play!Framework application with the following structure:
@Entity
public class User extends Model{
public User(String name, String email) {
UserConfig userConfig = new UserConfig(this);
userConfig.save();
}
}
@Entity
public class UserConfig extends Model{
@ManyToOne
public User user;
public UserOptions(User user) {
this.user = user;
}
I create an instance of User through CRUD's admin page (CRUD module for Play! framework).
I thought that CRUD will automatically create the instance of UserConfig, but it doesn't.
What should I do to make CRUD save the nested entity?
Upvotes: 0
Views: 630
Reputation: 13139
Use CascadeType attribute of ManyToMany or ManyToOne annotation. E.g. @ManyToOne(cascade = CascadeType.ALL).
More about the CascadeType here: http://docs.oracle.com/javaee/5/api/javax/persistence/CascadeType.html
Upvotes: 2