【问题标题】:Data save into MYSQL DB数据保存到 MYSQL DB
【发布时间】:2017-03-03 10:11:33
【问题描述】:

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

    [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 字段。

【问题讨论】:

  • 是的,txnId 是整数
  • 用正确的表检查一次映射

标签: mysql hibernate spring-mvc


【解决方案1】:

使用 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;
}

【讨论】:

    猜你喜欢
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2018-01-23
    • 2018-11-23
    • 2019-08-07
    • 1970-01-01
    • 2016-08-01
    相关资源
    最近更新 更多