2017-03-03 210 views
0

我得到下面的異常,而試圖在使用Spring MVC來保存數據到數據庫和休眠:數據保存到MySQL數據庫

[INFO] 2017-03-03 15:26:22,487 
stdout write - org.springframework.beans.InvalidPropertyException: 
Invalid property 'txnId' of bean class [com.entity.TxnCustomer]: Getter for property 'txnId' threw exception; nested exception is java.lang.reflect.InvocationTargetException 

實體的一部分:

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
@Column(name="TXN_ID") 
private Integer txnId; 


public TxnCustomer() { 
} 

public Integer getTxnId() { 
    return this.txnId; 
} 

public void setTxnId(Integer txnId) { 
    this.txnId = txnId; 
} 

我不明白爲什麼我會發生這種異常。

mysql數據庫包含txn_id字段,它被設置爲自動增量。

+0

'txnId'整數? – VPK

+0

是的,txnId是整數 –

+0

檢查一次你的映射與正確的表 – Vaibs

回答

0

使用int而不是整數

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
@Column(name="TXN_ID") 
private int txnId; 

public TxnCustomer() { 
} 

public int getTxnId() { 
    return this.txnId; 
} 

public void setTxnId(int txnId) { 
    this.txnId = txnId; 
} 
+0

解釋與答案將有利於答案 – RamPrakash