我知道有类似的问题,但我在java中找不到它,这是我的问题,我有一个名为" Transactions"它有一个自动生成的Id [COT_Id],我有和中间表[USER_TRANS],其中包含以下列:[COT_Id],[USER_Id],它在事务表和用户表之间建立关系,我需要在事务中插入一个新值它已经完成了,现在一旦插入,我需要获取自动生成的Id,以便将其插入中间表,这里是我的代码:
Transaction transaccion = new Transaction();
transaccion.setMvg_id(mvg_id);
aproCvv = generalService.getCardByCvv(cvv, cardNum);
transaccion.setCrd_id(aproCvv);
transaccion.setCot_amount(cot_amount);
transaccion.setCot_cuotas(cuotas);
transaccion.setCcr_id(ccr_id);
transaccion.setCot_authorizationNumber(numeroauto);
Date dateAct = new Date();
transaccion.setCot_CreateDate(dateAct);
transaccion.setEsb_id(esb_id);
transaccion.setCot_Ip(ipRemoto);
transaccion.setCot_cashUser(cot_cashUser);
transaccion.setCot_Reference(cot_Reference);
transaccion.setChn_id(chn_id);
transaccion.setCot_reverseReference("5454");
transaccion.setCot_transactionPin("566546df");
transaccion.setTrs_id(54);
if(resultado) {
transactionService.saveTrans(transaccion);
//here's where I need the autogenerated Id (transId)
generalService.saveUserTrans(udID, transId, 1);