2016-08-16 48 views
0

我被這個錯誤消息卡住了,每次我想要添加與另一個實體類的ManytoOne關係時都會出現此錯誤消息。沒有爲此實體層次結構定義的ID

該類必須使用一致的訪問類型(字段或屬性)。沒有這個實體層次

定義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; 

回答

1

JPA註釋都應該放置在任何領域或訪問方法。您已將@Id@GeneratedValue註釋放在字段(private Long id)上,但@ManyToOne@JoinColumns放在吸氣器(public Long getId())上。將後者移到一個字段上。

相關問題