In JPA 1.0 we did not get around to specifying a read-only mapping (in
fact we still haven't).
Because of that, using the insertable=false, updatable=false combination
in the @Column mapping became the de facto way of setting a mapping to
be read-only. It is not ideal since it requires setting multiple
physical column/join column attributes when a logical read-only option
would be the more appropriate option, but for the most part it has stuck
and is what most vendors support since it at least uses standard options
instead of a vendor-specific read-only annotation.
-Mike
On 17/01/2013 3:21 PM, Linda DeMichiel wrote:
> Hi Nicolas,
>
> On 1/14/2013 12:01 AM, Nicolas Seyvet wrote:
>> Hi,
>>
>> After using Hibernate for a while, I had assumed that insertable =
>> false and updatable = false where useful for supporting reuse of
>> columns across fields. But I got into an argument this week end with
>> someone saying that the JPA spec does not define how/if this is
>> mandated.
>>
>> Example:
>> @Entity
>> public class Company {
>>
>> @Id
>> @GeneratedValue(strategy = GenerationType.IDENTITY)
>> private Long id = null;
>> private String name = null;
>>
>> @OneToMany(cascade = CascadeType.ALL, mappedBy = "company")
>> private Set<Employee> employees = new HashSet<Employee>();
>>
>> [..]
>> }
>>
>> @Entity
>> public class Employee {
>>
>> @Id
>> @GeneratedValue(strategy = GenerationType.IDENTITY)
>> private Long id = null;
>> private String name = null;
>>
>> @ManyToOne()
>> @JoinColumn(name = "COMPANY_ID")
>> private Company company = null;
>>
>> // Reuse of the field for the FK id
>> @Column(name = "COMPANY_ID", insertable = false, updatable = false)
>> private Long companyId;
>>
>> }
>>
>> I went through the JPA 2.1 draft, can could not find anything
>> specific to this topic.
>>
>> Should this be clarified? Or was it discussed before I joined?
>>
>
> This was discussed back in the JPA 1.0 days. The semantics of
> insertable / updatable
> are defined in the Column annotation and are consistent with your use
> of them in the
> example above.
>
> -Linda
>
>
>> Best regards,
>> Nicolas Seyvet
>