If a field is annotated insertable=false
, updatable=false
, doesnt it mean that you cannot insert value nor change the existing value? Why would u want to do that?
Do you mean something like this BalusC?
@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/udpating 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. This is not really a technical, but more a semantic/natural decision.