时间戳字段之一的变化不是使gorm中的物体变脏
我有一个域类project
package priz.api.project
import groovy.transform.AutoClone
import net.kaleidos.hibernate.usertype.JsonbMapType
import priz.api.challenge.Challenge
import priz.api.model.AuditableEntity
import priz.api.security.User
import priz.api.workspace.Workspace
import net.kaleidos.hibernate.usertype.ArrayType
@AutoClone
class Project extends AuditableEntity {
String title
String description
String solution
String currentSituation
String disadvantages
String problemStatement
String successCriteria
User owner
User reviewer
Challenge challenge
Topic topic
ProjectCertificationStatus certificationStatus = ProjectCertificationStatus.None
Workspace workspace
ProjectStatus status
Map metaData
Date followupSentAt
Date lastWorkedOnAt
Date lastChangedAt
Date publishedAt
Long secondsUnpublishedChanges
Boolean open = false
String publicTitle
String publicDescription
String[] keywords
Map publicScopes
String posterUrl
String posterKey
Date deletedAt
User deletedBy
static transients = ['posterUrl']
static mapping = {
table 'project'
title type: 'text'
description type: 'text'
solution type: 'text'
currentSituation column: 'current_situation', type: 'text'
disadvantages type: 'text'
problemStatement type: 'text'
successCriteria column: 'success_criteria', type: 'text'
certificationStatus column: 'certification_status', enumType: 'string'
status column: 'status', enumType: 'string'
metaData type: JsonbMapType
followupSentAt column: 'followup_sent_at'
lastWorkedOnAt column: 'last_worked_on_at'
publicTitle column: 'public_title', type: 'text'
publicDescription column: 'public_description', type: 'text'
keywords column: 'keywords', type: ArrayType, params: [type: String]
publicScopes column: 'public_scopes', type: JsonbMapType
posterKey column: 'poster_key', type: 'text'
lastChangedAt column: 'last_changed_at'
publishedAt column: 'published_at'
secondsUnpublishedChanges formula: 'EXTRACT(EPOCH FROM (last_changed_at - published_at))'
autoTimestamp true
}
static constraints = {
title nullable: false, blank: false, size: 3..5000
description nullable: true
solution nullable: true
currentSituation nullable: true
disadvantages nullable: true
problemStatement nullable: true
successCriteria nullable: true
owner nullable: false
reviewer nullable: true
challenge nullable: true
topic nullable: true
certificationStatus nullable: false
status nullable: false
createdBy nullable: false
workspace nullable: false
metaData nullable: true
followupSentAt nullable: true
lastWorkedOnAt nullable: true
lastChangedAt nullable: true
publishedAt nullable: true
open nullable: false
publicTitle nullable: true, black: true
publicDescription nullable: true, black: true
keywords nullable: true, black: true
publicScopes nullable: true, black: true
posterKey nullable: true, black: true
}
}
字段lastchangedat
假设在项目中发生任何东西时,最后一次陷入困境。因此,我们正在使用Publisher/订阅来解雇事件并聆听它们以进行此更新。最终,侦听器正在调用此功能:
Project updateLastChangedAt(Project project) {
project.lastChangedAt = new Date()
project.save()
}
简单...
问题是lastchangedat
字段未在DB中更新。对此进行调试,我发现即使字段值在变化,project
对象仍然被认为不脏。
为什么会这样?对于所有其他字段的变化,一切都按预期工作。
更新
显然,我收到以下错误:
cannot execute UPDATE in a read-only transaction
这是我第一次看到这个:( 这两种方法都是交易的,所以我什至无法想到为什么这是一项仅阅读交易。
Optional<Project> updateLastChangedAt(Long projectId) {
projectRepositoryService.dangerousGet(projectId).map { updateLastChangedAt(it) }
}
Project updateLastChangedAt(Project project) {
project.lastChangedAt = new Date()
project.save(flush: true)
}
I have a domain class Project
package priz.api.project
import groovy.transform.AutoClone
import net.kaleidos.hibernate.usertype.JsonbMapType
import priz.api.challenge.Challenge
import priz.api.model.AuditableEntity
import priz.api.security.User
import priz.api.workspace.Workspace
import net.kaleidos.hibernate.usertype.ArrayType
@AutoClone
class Project extends AuditableEntity {
String title
String description
String solution
String currentSituation
String disadvantages
String problemStatement
String successCriteria
User owner
User reviewer
Challenge challenge
Topic topic
ProjectCertificationStatus certificationStatus = ProjectCertificationStatus.None
Workspace workspace
ProjectStatus status
Map metaData
Date followupSentAt
Date lastWorkedOnAt
Date lastChangedAt
Date publishedAt
Long secondsUnpublishedChanges
Boolean open = false
String publicTitle
String publicDescription
String[] keywords
Map publicScopes
String posterUrl
String posterKey
Date deletedAt
User deletedBy
static transients = ['posterUrl']
static mapping = {
table 'project'
title type: 'text'
description type: 'text'
solution type: 'text'
currentSituation column: 'current_situation', type: 'text'
disadvantages type: 'text'
problemStatement type: 'text'
successCriteria column: 'success_criteria', type: 'text'
certificationStatus column: 'certification_status', enumType: 'string'
status column: 'status', enumType: 'string'
metaData type: JsonbMapType
followupSentAt column: 'followup_sent_at'
lastWorkedOnAt column: 'last_worked_on_at'
publicTitle column: 'public_title', type: 'text'
publicDescription column: 'public_description', type: 'text'
keywords column: 'keywords', type: ArrayType, params: [type: String]
publicScopes column: 'public_scopes', type: JsonbMapType
posterKey column: 'poster_key', type: 'text'
lastChangedAt column: 'last_changed_at'
publishedAt column: 'published_at'
secondsUnpublishedChanges formula: 'EXTRACT(EPOCH FROM (last_changed_at - published_at))'
autoTimestamp true
}
static constraints = {
title nullable: false, blank: false, size: 3..5000
description nullable: true
solution nullable: true
currentSituation nullable: true
disadvantages nullable: true
problemStatement nullable: true
successCriteria nullable: true
owner nullable: false
reviewer nullable: true
challenge nullable: true
topic nullable: true
certificationStatus nullable: false
status nullable: false
createdBy nullable: false
workspace nullable: false
metaData nullable: true
followupSentAt nullable: true
lastWorkedOnAt nullable: true
lastChangedAt nullable: true
publishedAt nullable: true
open nullable: false
publicTitle nullable: true, black: true
publicDescription nullable: true, black: true
keywords nullable: true, black: true
publicScopes nullable: true, black: true
posterKey nullable: true, black: true
}
}
The field lastChangedAt
suppose to holed the last time when there was anything changed in the project. So, we are using Publisher/Subscrip to fire the events and listen to them to make this update. Eventually, the listener is calling this function:
Project updateLastChangedAt(Project project) {
project.lastChangedAt = new Date()
project.save()
}
simple...
The problem is that the lastChangedAt
field is not getting updated in DB. Debugging this, I saw that even though the field value is changing, the project
object is still considered not dirty.
Why could that be? For all the other field changes, everything works as expected.
UPDATE
Apparently, I am getting the following error:
cannot execute UPDATE in a read-only transaction
It's the first time I see this one :(
Both of these methods are Transactional, so I can't even think about why would it be a read-only transaction.
Optional<Project> updateLastChangedAt(Long projectId) {
projectRepositoryService.dangerousGet(projectId).map { updateLastChangedAt(it) }
}
Project updateLastChangedAt(Project project) {
project.lastChangedAt = new Date()
project.save(flush: true)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了这个问题...不确定我是如何错过的。
我的听众服务的交易设置为仅阅读设置为true
Found the issue... Not sure how I missed it.
My listener service had Transactional set to read-only set to true