Skip to content

Registering entities explicitly should override annotations. #190

Description

@linderl

I would like to be able to define a @transient id method on my entity class that should be used by JaVers for retrieving the id.
Here is a test that describes what i need.

/**
 * Created by patlin on 2015-08-19.
 */

public class JaVersTest {
    @Entity
    @Value
    @Builder
    public static class MyEntityWithTransientIdMember {
        String id;
        String name;
        @Id
        public String getId() {
            return id;
        }
        @Transient
        public String getUniqueKey() {
            return id + "/" + name;
        }
    }
    @Entity
    @Value
    @Builder
    public static class MyEntityWithNonTransientIdMember {
        String id;
        String name;
        @Id
        public String getId() {
            return id;
        }

        public String getUniqueKey() {
            return id + "/" + name;
        }
    }
    @Test
    // This test fails, but this is what I need.
    public void registeringExplicitlyShouldOverrideAnnotation() {
        Javers javers = JaversBuilder.javers().withMappingStyle(MappingStyle.BEAN).
                registerEntity(new EntityDefinition(MyEntityWithTransientIdMember.class, "uniqueKey")).build();
        MyEntityWithTransientIdMember my = MyEntityWithTransientIdMember.builder().id("17").name("Rod").build();
        try {
            javers.commit("user", my);
        } catch (JaversException je) {
            Assert.fail("Registering entity with specified id property name does not override annotation");
        }
    }
    @Test
    // This test will pass.
    public void registeringExplicitlyShouldOverrideAnnotation2() {
        Javers javers = JaversBuilder.javers().withMappingStyle(MappingStyle.BEAN).
                registerEntity(new EntityDefinition(MyEntityWithNonTransientIdMember.class, "uniqueKey")).build();
        MyEntityWithNonTransientIdMember my = MyEntityWithNonTransientIdMember.builder().id("17").name("Rod").build();
        try {
            javers.commit("user", my);
        } catch (JaversException je) {
            Assert.fail("Registering entity with specified id property name does not override annotation");
        }
    }
}

Activity

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions