Please, explain for what purpose @Transient was placed on getter and setter methods at the same time as @Column was placed on field. The field is stored to DB as we need.
@Entity
@Table(name = "person")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "name")
private String name;
@Transient
public long getName() {
return name;
}
@Transient
public void setName(String name) {
this.name = name;
}
}
In the code as you have it, they have no effect, since the @Id on a field causes the default access to be field, thus ignoring any method annotations. If property access was the default (either by @Id on the getter or @Access(PROPERTY) on the class), the @Transient annotations would cause JPA to ignore the accessors, presumably so that the field mapping could be picked up. However, in that case, the field should be annotated with @Access(FIELD).
I'd say the @Transient annotations are leftovers from a time when the entity had default property access.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With