gorm-hibernate5 icon indicating copy to clipboard operation
gorm-hibernate5 copied to clipboard

bug: no update on child values

Open caladol1 opened this issue 8 years ago • 4 comments

I found a bug on gormVersion=6.1.7.RELEASE I updated it from 6.1.5.RELEASE where it also happened

example code:

 Product.withTransaction {
            Pro2t domainObject= Pro2t .get(id)
                //domainObject.internal= "something1"  // this level updates are ok
                domainObject.child.interna2 = "something2"  // second level does not triguer update
                domainObject.save(flush: true, validate: false)
        }

caladol1 avatar Oct 19 '17 07:10 caladol1

Provide an example that reproduces the issue

graemerocher avatar Oct 19 '17 09:10 graemerocher

She example data structure: would be

package com.my.web
import groovy.transform.CompileStatic
import javax.persistence.*

@CompileStatic
@grails.gorm.annotation.JpaEntity
class Pro2t   {

    String internal

    @Embedded
    Re2a child

    Re2a getChild() { return (this.@child ?: (this.@child= new Re2a())) }

    @GeneratedValue
    @Id
    Long id

    @Version
    Long version

}
package com.my.web
import groovy.transform.CompileStatic
import javax.persistence.*

@CompileStatic
@Embeddable
@MappedSuperclass
class Re2a implements Serializable, Cloneable{
    Re2a(){}

    String internal2

}

caladol1 avatar Oct 19 '17 09:10 caladol1

I could resolve the issue by manually applying @grails.gorm.dirty.checking.DirtyCheck to the embeddable class. @graemerocher: Is this behaviour intended? Could it be applied automatically for all classes marked with @javax.persistence.Embeddable? Are transformation like @DirtyCheck part of public API that can be used by custom code?

ivo-k avatar Apr 27 '18 14:04 ivo-k

@DirtyCheck is part of the public API yes and should be applied. We could probably apply for classes marked as Embeddable automatically that would be a nice improvement

graemerocher avatar Apr 27 '18 14:04 graemerocher