gpt4 book ai didi

java - PLAY 中嵌套对象的自动 save()!日本PA

转载 作者:行者123 更新时间:2023-12-02 07:54:02 25 4
gpt4 key购买 nike

我有一个具有以下结构的 Play!Framework 应用程序:

@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;
}

我通过 CRUD 的管理页面(Play! 框架的 CRUD 模块)创建了一个 User 实例。

我以为CRUD会自动创建UserConfig的实例,但事实并非如此。

我应该怎么做才能让 CRUD 保存嵌套实体?

最佳答案

使用ManyToMany或ManyToOne注释的CascadeType属性。例如。 @ManyToOne(级联 = CascadeType.ALL)。

<小时/>

有关 CascadeType 的更多信息:http://docs.oracle.com/javaee/5/api/javax/persistence/CascadeType.html

关于java - PLAY 中嵌套对象的自动 save()!日本PA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9875639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com