gpt4 book ai didi

mysql - 数据保存到MYSQL DB

转载 作者:行者123 更新时间:2023-11-29 19:18:26 25 4
gpt4 key购买 nike

我在尝试使用 spring MVC 和 hibernate 将数据保存到数据库时遇到以下异常:

    [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字段,该字段设置为自动递增。

最佳答案

使用 int 代替 Integer

@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;
}

关于mysql - 数据保存到MYSQL DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42576054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com