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

Registering entities explicitly should override annotations. #190

Closed
linderl opened this Issue Aug 19, 2015 · 8 comments

Comments

Projects
None yet
2 participants
@linderl

linderl commented Aug 19, 2015

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");
        }
    }
}

@bartoszwalacik bartoszwalacik added the bug label Aug 22, 2015

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Aug 22, 2015

will check it, you are right that explicit EntityDefinition should override annotations

@bartoszwalacik bartoszwalacik self-assigned this Aug 22, 2015

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Aug 23, 2015

so you want to use getUniqueKey() property as Entity Id even if it has @Transient annotation

@linderl

This comment has been minimized.

linderl commented Aug 23, 2015

Yes, that is correct. Otherwise I would have have to create a dummy column
in the database so that Hibernate can map the entity.
Den 23 aug 2015 10:14 skrev "Bartosz Walacik" notifications@github.com:

so you want to use getUniqueKey() property as Entity Id even if it has
@transient annotation


Reply to this email directly or view it on GitHub
#190 (comment).

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Aug 23, 2015

Ok, I am working on the fix

bartoszwalacik added a commit that referenced this issue Aug 23, 2015

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Aug 24, 2015

fixed in release 1.3.4

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Aug 24, 2015

give us a star if you like javers https://github.com/javers/javers/stargazers

@linderl

This comment has been minimized.

linderl commented Aug 24, 2015

Thank you for fixing this issue. It really makes a big difference for us when trying out the JaVers library. Unfortunately i found another bugg. #192

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Aug 24, 2015

ok, thanks for reporting #192, will check it

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