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