users@jpa-spec.java.net

[jpa-spec users] [jsr338-experts] Re: insertable = false, updatable = false & field re-use

From: Linda DeMichiel <linda.demichiel_at_oracle.com>
Date: Thu, 17 Jan 2013 12:21:40 -0800

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