AnnotatedGetterIdPropertyResolver implements IdPropertyResolver { @Override public String resolve(final Class<?> entityType, Class<?> idType) { final AtomicReference<Method> found = new AtomicReference<>(); ReflectionUtils.doWithMethods(entityType, method -> { if (isAnnotated(method)) { if (found.get() == null) { found.set(method); } else { throw new MultipleIdPropertiesException(entityType); } } }, new GetterMethodFilter()); final Method idAnnotatedMethod = found.get(); return getPropertyNameFromAnnotatedMethod(entityType, idType, idAnnotatedMethod); }  @Override String resolve(final Class<?> entityType, Class<?> idType);  }
@Test public void testResolvingIdPropertyWhenIdAnnotationOnGetterIsFromJPA() { final String property = getIdPropertyResolver().resolve(EntityWithAnnotatedIdGetterFromJPA.class, Integer.class); assertThat(property, is(notNullValue())); assertThat(property, is("myCustomId")); }
@Test public void testResolvingIdPropertyWhenEmbeddedIdAnnotationOnGetterIsFromJPA() { final String property = getIdPropertyResolver().resolve(EntityWithAnnotatedEmbeddedIdGetterFromJPA.class, EmbeddableId.class); assertThat(property, is(notNullValue())); assertThat(property, is("myCustomId")); }