AnnotatedFieldIdPropertyResolver implements IdPropertyResolver { @Override public String resolve(final Class<?> entityType, Class<?> idType) { final AtomicReference<Field> found = new AtomicReference<>(); ReflectionUtils.doWithFields(entityType, field -> { if (isAnnotated(field)) { if (found.get() == null) { found.set(field); } else { throw new MultipleIdPropertiesException(entityType); } } }); final Field idAnnotatedField = found.get(); if (idAnnotatedField != null) { if (!PropertyUtils.getTypeOf(idType).isAssignableFrom( PropertyUtils.getTypeOf(idAnnotatedField.getType()))) { throw new PropertyTypeMismatchException(entityType, idAnnotatedField.getName(), idType, idAnnotatedField.getType()); } else { return idAnnotatedField.getName(); } } return null; }  @Override String resolve(final Class<?> entityType, Class<?> idType);  }
@Test public void testResolvingIdPropertyWhenIdAnnotationOnFieldIsFromJPA() { final String property = getIdPropertyResolver().resolve(EntityWithAnnotatedIdFieldFromJPA.class, Long.class); assertThat(property, is(notNullValue())); assertThat(property, is("customIdProperty")); }
@Test public void testResolvingEmbeddedIdPropertyWhenIdAnnotationOnFieldIsFromJPA() { final String property = getIdPropertyResolver().resolve(EntityWithAnnotatedEmbeddedIdFieldFromJPA.class, EmbeddableId.class); assertThat(property, is(notNullValue())); assertThat(property, is("customIdProperty")); }