[英]One of the timestamp fields change is not making the object dirty in gorm
I have a domain class Project
我有一个域类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. lastChangedAt
字段假设最后一次在项目中有任何更改时出现。 So, we are using Publisher/Subscrip to fire the events and listen to them to make this update.因此,我们使用 Publisher/Subscrip 来触发事件并监听它们以进行更新。 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.问题是lastChangedAt
字段没有在数据库中更新。 Debugging this, I saw that even though the field value is changing, the project
object is still considered not dirty.调试这个,我看到即使字段值发生变化, project
对象仍然被认为是不脏的。
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)
}
Found the issue... Not sure how I missed it.找到了问题...不知道我是怎么错过的。 My listener service had Transactional set to read-only set to true我的侦听器服务将 Transactional 设置为只读设置为 true
@Transactional(readOnly = true)
class ProjectLastChangedListenerService {
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.