我遇到了这个错误消息,每次我想要与另一个实体类添加ManytoOne关系时都会出现。
该类必须使用一致的访问类型(字段或属性)。没有为此实体层次结构定义ID
这是我的实体交易
@Entity
@Table(name = "CustomerTransaction")
public class CustomerTransaction implements Serializable {//this is the line with the error message
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne //This generates the problem
@JoinColumns({
@JoinColumn(name = "CUS_ID", referencedColumnName = "IDCUSTOMER") })
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private long transactionID;
@Temporal(TemporalType.TIMESTAMP)
private Date buyDate;
public Date getBuyDate() {
return buyDate;
}
public void setBuyDate(Date buyDate) {
this.buyDate = buyDate;
}
public long getTransactionID() {
return transactionID;
}
public void setTransactionID(long transactionID) {
this.transactionID = transactionID;
}
public String getCarYear() {
return carYear;
}
public void setCarYear(String carYear) {
this.carYear = carYear;
}
public Date getTransactionDate() {
return transactionDate;
}
public void setTransactionDate(Date transactionDate) {
this.transactionDate = transactionDate;
}
private String carYear;
@Temporal(TemporalType.TIMESTAMP)
private Date transactionDate;
答案 0 :(得分:4)
JPA注释应全部放在字段或访问器方法上。您已将@Id
和@GeneratedValue
注释放置在字段(private Long id
)上,但@ManyToOne
和@JoinColumns
放置在获取者(public Long getId()
)上。将后者也移动到一个字段上。