请参考 JPA @Column 注释解释 insertable=false 和 updatable=false [英] Please explain about insertable=false and updatable=false in reference to the JPA @Column annotation

查看:51
本文介绍了请参考 JPA @Column 注释解释 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;
}

推荐答案

当创建/更新引用列的责任不在当前 实体,但在另一个实体中.

You would do that when the responsibility of creating/updating the referenced column isn't in the current entity, but in another entity.

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

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