users@jpa-spec.java.net

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

From: Nicolas Seyvet <nicolas.seyvet_at_ericsson.com>
Date: Mon, 14 Jan 2013 08:01:55 +0000

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?

Best regards,
Nicolas Seyvet