Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.
In entity bean, the foreign key usually replaced by the referential relationship such as :
public class Status implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name="creation_datetime", nullable = false)
private Timestamp creationDatetime;
@Id
@Column(name="seq_no", nullable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer seqNo;
@Column(name="status", nullable = false)
private String status;
@Column(name="car_id", nullable = false, insertable=false, updatable=false)
private String carId;
@ManyToOne
@JoinColumn(name = "car_id")
private Transaction transaction;
public Status() {
}
public Status(Timestamp creation_datetime,
Transaction transaction,
Integer seqNo, String status, String carId) {
this.creationDatetime = creation_datetime;
this.transaction = transaction;
this.seqNo = seqNo;
this.status = status;
this.carId = carId;
}
}
The foreign key is carId. It is exists in the relationship
@ManyToOne
@JoinColumn(name = "car_id")
private Transaction transaction;
Eclipse will not generate the carId field for you. You required to explicitly create a read only field by annotation insertable=false, updatable=false. Otherwise, exception: Multiple writable mappings exist for the field [status.car_id]. Only one may be defined as writable, all others must be specified read-only will be thrown.
public class Status implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name="creation_datetime", nullable = false)
private Timestamp creationDatetime;
@Id
@Column(name="seq_no", nullable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer seqNo;
@Column(name="status", nullable = false)
private String status;
@Column(name="car_id", nullable = false, insertable=false, updatable=false)
private String carId;
@ManyToOne
@JoinColumn(name = "car_id")
private Transaction transaction;
public Status() {
}
public Status(Timestamp creation_datetime,
Transaction transaction,
Integer seqNo, String status, String carId) {
this.creationDatetime = creation_datetime;
this.transaction = transaction;
this.seqNo = seqNo;
this.status = status;
this.carId = carId;
}
}
The foreign key is carId. It is exists in the relationship
@ManyToOne
@JoinColumn(name = "car_id")
private Transaction transaction;
Eclipse will not generate the carId field for you. You required to explicitly create a read only field by annotation insertable=false, updatable=false. Otherwise, exception: Multiple writable mappings exist for the field [status.car_id]. Only one may be defined as writable, all others must be specified read-only will be thrown.
留言
張貼留言