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;