请解释一下:insertable = false,updatable = false [英] Please explain about: insertable=false, updatable=false

查看:662
本文介绍了请解释一下:insertable = false,updatable = false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果某个字段已注释 insertable = false,updatable = false ,这是否意味着您不能插入值也不能更改现有值?你为什么要这样做?

If a field is annotated insertable=false, updatable=false, doesn't it mean that you cannot insert value nor change the existing value? Why would you want to do that?

@Entity
public class Person {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToMany(mappedBy="person", cascade=CascadeType.ALL)
    private List<Address> addresses;
}

@Entity
public class Address {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne
    @JoinColumn(name="ADDRESS_FK")
    @Column(insertable=false, updatable=false)
    private Person person;
}


推荐答案

你会这样做的创建/更新相关实体的责任不在当前实体中。例如。你有地址。您想将 insertable = false,updatable = false 添加到 @OneToMany 与<$ c $的关系c>人 地址实体中的实体,仅仅因为它不是地址实体创建或更新。反之亦然。

You would do that when the responsibility of creating/updating the related entity in question isn't in the current entity. E.g. you have a Person and an Address. You'd like to add insertable=false, updatable=false to the @OneToMany relationship with the Person entity in the Address entity, simply because it's not the responsibility of the Address entity to create or update a Person. It's the other way round.

这篇关于请解释一下:insertable = false,updatable = false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆