Skip to content
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
Closed

Registering entities explicitly should override annotations. #190

linderl opened this issue Aug 19, 2015 · 8 comments
Assignees
Labels

Comments

@linderl
Copy link

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
Copy link
Member

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

@bartoszwalacik bartoszwalacik self-assigned this Aug 22, 2015
@bartoszwalacik
Copy link
Member

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

@linderl
Copy link
Author

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
Copy link
Member

Ok, I am working on the fix

@bartoszwalacik
Copy link
Member

fixed in release 1.3.4

@bartoszwalacik
Copy link
Member

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

@linderl
Copy link
Author

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
Copy link
Member

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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants