ssh轉賬時,插入兩條資料進表,並更新資料
阿新 • • 發佈:2019-01-04
private void turnIn(String toCardno, float money) {
accountDao.turnIn(toCardno, money);
//轉入賬戶
float balance=accountDao.getBalance(toCardno);
System.out.println("轉入賬戶餘額="+balance);
Transaction transaction=new Transaction();
Date date=new Date();
transaction.setCardno (toCardno);
transaction.setTransaction_date(date);
transaction.setExpense(money);
transaction.setBalance(balance);
transaction.setTransaction_type("轉入");
System.out.println("執行插入insertRecord");
transactionDao.insertRecord(transaction);
}
出現這個問題
org.springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : [entity.Transaction#0]; nested exception is
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [entity.Transaction#0]
但是,我在實體類上加上 –紅色的部分
即主鍵的生成策略後就不報錯了
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@Column(name = “id”)
private int id;