Kam*_*ian 3 spring hibernate kotlin spring-boot
我不明白,我的服务出了什么问题。我收到org.hibernate.StaleObjectStateException
尝试运行此方法:
fun updateNameForPhone(phone: String, name: String): Client {
val res = clientRepository.findByPhone(phone) ?: throw ClientNotFoundException(phone)
res.name = name
return clientRepository.save(res)
}
Run Code Online (Sandbox Code Playgroud)
客户端存储库:
@Repository
interface ClientRepository : JpaRepository<Client, UUID> {
fun findByPhone(phone: String): Client?
}
Run Code Online (Sandbox Code Playgroud)
客户实体:
@Entity
data class Client(
var name: String = "",
var phone: String = "",
@Id @GeneratedValue(strategy = GenerationType.AUTO)
val uuid: UUID = defaultUuid()
)
Run Code Online (Sandbox Code Playgroud)
例外:
类 [com.app.modules.client.domain.Client] 的对象,标识符为 [12647903-7773-4f07-87a8-e9f86e99aab3]:乐观锁定失败;嵌套异常是 org.hibernate.StaleObjectStateException:行已被另一个事务更新或删除(或未保存值映射不正确):[com.app.modules.client.domain.Client#12647903-7773-4f07-87a8-e9f86e99aab3] ”
是什么原因?我正在使用 Kotlin 1.3.11、Spring Boot 2.1.1、MySql。我不在不同的线程中运行它,只是尝试单个请求。
归档时间: |
|
查看次数: |
17051 次 |
最近记录: |