New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Bean Mapping Style due to Type Erasure #457

Closed
ianagius opened this Issue Nov 15, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@ianagius
Contributor

ianagius commented Nov 15, 2016

When using Bean MappingStyle (using @id on getters), an issue is being encountered with the use of the @id annotation on an extended generic method. This results in an ENTITY_WITHOUT_ID Exception ("Class '%s' mapped as Entity has no Id property. Use @id annotation to mark unique and not-null Entity identifier") being thrown.

This can be easily replicated when we have an abstract Parent class that defines a getter method which is overridden by a child class getter annotated with @id. Example:

public abstract class AbstractEntity<ID extends Serializable> {
    public abstract ID getId();
}

and child:

public class Entity extends AbstractEntity<Long> {
    private Long id;

    public Entity(Long id) {
        this.id = id;
    }

    @Id
    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}

Due to type erasure and generated bridge method (https://docs.oracle.com/javase/tutorial/java/generics/bridgeMethods.html), the following methods will be generated:

public java.io.Serializable org.javers.core.model.Entity.getId(); // bridge method
public java.lang.long org.javers.core.model.Entity.getId(); // our method with @Id annotation
public java.lang.long org.javers.core.model.Entity.setId();

In JaversMethodFactory.getAllMethods(), sometimes this method processes the 'bridge' method first, before our method, and this results in our method to be skipped since the logic filters inheritance duplicates. A suggested solution is to skip the bridge method, thus our method can be added.

PR with failing test case and proposed solution will be pushed soon.

@ianagius

This comment has been minimized.

Contributor

ianagius commented Nov 15, 2016

created the following pull request #458

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Nov 16, 2016

@ianagius thanks for excelent issue description and the PR. I'll try to merge this evening

bartoszwalacik added a commit that referenced this issue Nov 16, 2016

@ianagius

This comment has been minimized.

Contributor

ianagius commented Nov 16, 2016

cheers

@bartoszwalacik bartoszwalacik added the bug label Nov 16, 2016

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Nov 16, 2016

merged, your fix will be released tomorrow

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Nov 17, 2016

fix released in 2.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment