简体   繁体   中英

Groovy traits doesn't have generated default getters and setters as documented

According to documentation of Groovy the behavior of getters and setters generating should be similar to common classes. But I have an issue ... common Groovy classes do have these getters and setters generated in my code but I need to write explicit setters and getters or my code does not compile.

@MappedSuperclass
trait Versioned {
    @Version
    @Column(name = "VERSION", nullable = false)
    Long version
}

When another grrovy class implemented the trait the message was:

"error: PersistentCommand is not abstract and does not override abstract method setVersion(Long) in Versioned"

My Groovy is older (2.4.15) but the rest is now up to date IntelliJ Idea 2020.2.3, Gradle 6.7. By the way I have checked traits documentation of exact Groovy version I use. Any idea what could be the problem?

Thank you

this is not an answer. i just want to show that your code works.

@Grab(group='javax.persistence', module='javax.persistence-api', version='2.2')
import javax.persistence.MappedSuperclass
import javax.persistence.Version
import javax.persistence.Column

@MappedSuperclass
trait Versioned {
    @Version
    @Column(name = "VERSION", nullable = false)
    Long version
}

@groovy.transform.ToString
class V implements Versioned{
    String name
}

def v=new V(version:123,name:"world")

So after some experimenting I can confirm my suspect. The problem was groovy version that was too old and probably caused some issues. With groovy 2.5.13 it behaves as expected

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM