【发布时间】:2019-05-28 14:15:18
【问题描述】:
根据我的要求,我的字段具有自动增量&不是键。在调用存储库 save() 后,我需要获取该自动增量字段的值。
merchantEntity = merchantRepository.save(merchantEntity);
merchantEntity.getMerchId() // returns null
但是有些我没有得到自动增量字段的值,它返回 null。 这是我的实体类。
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id")
private Integer merchId;
我尝试过使用其他几种解决方法,例如在保存后立即刷新实体。但结果是一样的。
merchantEntity = merchantRepository.saveAndFlush(entity); // still returns null
merchantEntity = merchantRepository.save(entity);
merchantRepository.flush();
MerchantEntity toBeUpdatedMerchantEntity =
merchantRepository.findOne(merchantEntity.getId()); // still returns null
是否有可能实现我的期望。非常感谢任何帮助。 谢谢
【问题讨论】:
标签: java spring-boot jpa spring-data-jpa