grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

Gorm 6.1 JPA @Version duplication

Open ryancornia opened this issue 7 years ago • 1 comments

In migrating a grails 3.2.11 app to 3.3.8, which migrates to Gorm 6.1, JPA annotated entities no longer work.

TagLink.groovy

import javax.persistence.*;
import javax.validation.constraints.Min;

@Entity
@Table(name = "tag_links")
public class TagLink {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch=FetchType.EAGER, cascade = [CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.MERGE])
    @JoinColumn(name = "tag_id")
    private Tag tag;

    @Column(name = "tag_ref")
    @Min(0L)
    private Long tagRef;

    @Column(name = "type", nullable = false)
    private String type;

    @Version
    private Long version;
...

Fails on build with:

The method public java.lang.Long getVersion() { ... } duplicates another method of the same signature . At [-1:-1] @ line -1, column -1.

All of my JPA entities that have an @Version annotation fail.

I would assume if Gorm 6.1 supports JPA annotations, it should handle the @Version annotation.

ryancornia avatar Dec 02 '18 19:12 ryancornia

I have a similar issue. It looks like that DirtyCheckingTransformer generates a getVersion() method that always returns 0 if no 'version' property (not field) is defined in this class. It is also ignoring definitions in base classes.

https://github.com/grails/grails-data-mapping/blob/6e6dbaab43aa316bea1a6e832a1321925d319825/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/DirtyCheckingTransformer.groovy#L254-L266

I guess adding

 && !GrailsASTUtils.hasOrInheritsProperty(classNode, GormProperties.VERSION);

to the if statement could at least solve my problem.

ivo-k avatar Nov 05 '19 16:11 ivo-k