ebean-orm / ebean

Ebean ORM
https://ebean.io
Apache License 2.0
1.47k stars 260 forks source link

`@OneToOne` cascade persistence does not work #3525

Closed kevin70 closed 3 hours ago

kevin70 commented 4 hours ago

Expected behavior

Save users data and save wechat_profile

Actual behavior

Only save users data

Steps to reproduce

@Getter
@Setter
@Entity
@Table(name = "users")
public class User {

    /// 主键
    @Id
    @GeneratedValue
    private Long id;
    /// 创建时间
    @WhenCreated
    private Instant createTime;
    /// 更新时间
    @WhenModified
    private Instant updateTime;
    /// 软删除
    @SoftDelete
    private Boolean deleted;
    /// 头像地址
    private String avatar;
    /// 昵称
    private String nickname;
    /// 手机
    private String mobile;

    /// 微信个人信息
    @OneToOne(cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
    private WechatProfile wechatProfile;
}

@Getter
@Setter
@Entity
@Table(name = "wechat_profile")
public class WechatProfile {

    /// 主键
    @Id
    private Long id;
    /// 创建时间
    @WhenCreated
    private Instant createTime;
    /// 更新时间
    @WhenModified
    private Instant updateTime;
}
12-02T18:35:45.344 D [Test worker] io.ebean.SQL 128; txn[1001] insert into users (avatar, nickname, mobile, create_time, update_time, deleted) values (?,?,?,?,?,?); -- bind(ZHLWOYEE,JAZRS,VQLQETHDUI,2024-12-02T10:35:43.604Z,2024-12-02T10:35:43.604Z,false)
12-02T18:35:45.357 D [Test worker] io.ebean.SUM 128; txn[1001] Inserted [User] [20]
12-02T18:35:47.133 D [Test worker] io.ebean.TXN 128; txn[1001] Commit
kevin70 commented 3 hours ago

Sorry, it's my fault. Using standard JPA mapping can correctly cascade and save.