【发布时间】:2021-11-03 06:39:41
【问题描述】:
我现在正在尝试使用“getById & save”来更新实体的列,如下所示。
// update "title" column
val entityRef = entityRepository.getById(entityID)
entityRef.title = futureTitle
return entityRepository.save(entityRef)
但是,如果我运行代码,即使该列已完美更新,updatedtimestamp 列(描述为CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)也不会改变。
似乎updatedtimestamp 列仅在我使用自定义“UPDATE”查询时才会更新。
@Modifying
@Transactional
@Query("update Entity p set p.title = :newTitle where p.id = :entityId")
fun updateEntityTitle(entityId: Long, newTitle: String)
我能知道为什么通过“getById & save”更新实体没有改变updatedtimestamp吗?
提前致谢!
【问题讨论】:
标签: mysql jpa spring-data-jpa