Ok that is good.
But this is a typical instance of a table field being re-used within an entity.
Let's say, there is a table A with three columns id, col1 and col2.
A
| id |col1 | col2|
Is the following legal according to the spec?
@Entity
public class AEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id = null;
@Column(name = "col1 ")
private String col1;
private String col2;
@Column(name = "col1 ", insertable = false, updatable = false)
private String col3 = null;
[..]
}
If not, should it be covered in the spec?
-----Original Message-----
From: Linda DeMichiel [mailto:linda.demichiel_at_oracle.com]
Sent: Thursday, January 17, 2013 9:22 PM
To: jsr338-experts_at_jpa-spec.java.net
Subject: [jsr338-experts] Re: insertable = false, updatable = false & field re-use
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