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)
}