6464public class PojoRepositoryImpl <T , ID extends Serializable >
6565 implements PojoRepository <T , ID >
6666{
67+ private static final Pattern getterPattern = Pattern .compile ("^(get|is)(.)(.*)" );
6768 private final String EXTENSION = ".json" ;
6869
6970 private DatabaseClient client ;
@@ -416,6 +417,14 @@ private void findId() {
416417 idMethod = getter ;
417418 break ;
418419 }
420+ if ( property .hasSetter () ) {
421+ Method setter = property .getSetter ().getAnnotated ();
422+ if ( setter .getAnnotation (Id .class ) != null ) {
423+ idPropertyName = property .getName ();
424+ idMethod = getter ;
425+ break ;
426+ }
427+ }
419428 }
420429 // setter only doesn't work because it gives us no value accessor
421430 }
@@ -427,26 +436,37 @@ private void findId() {
427436 if ( method .isAnnotationPresent (Id .class ) ) {
428437 Class <?>[] parameters = method .getParameterTypes ();
429438 if ( ! Modifier .isPublic (method .getModifiers ()) ) {
430- throw new IllegalStateException ("Your getter method, " + method .getName () +
439+ throw new IllegalStateException ("Your method, " + method .getName () +
431440 ", annotated with com.marklogic.client.pojo.annotation.Id " +
432441 " must be public" );
433442 }
434443 if ( parameters == null || parameters .length == 0 ) {
435- Pattern pattern = Pattern .compile ("^(get|is)(.)(.*)" );
436- Matcher matcher = pattern .matcher (method .getName ());
444+ Matcher matcher = getterPattern .matcher (method .getName ());
437445 if ( matcher .matches () ) {
438446 idPropertyName = matcher .group (2 ).toLowerCase () + matcher .group (3 );
439447 idMethod = method ;
440448 break ;
441449 } else {
442- throw new IllegalStateException ("Your getter method, " + method .getName () +
450+ throw new IllegalStateException ("Your no-args method, " + method .getName () +
443451 ", annotated with com.marklogic.client.pojo.annotation.Id " +
444452 " must be a proper getter method and begin with \" get\" or \" is\" " );
445453 }
446454 } else {
447- throw new IllegalStateException ("Your getter method, " + method .getName () +
448- ", annotated with com.marklogic.client.pojo.annotation.Id " +
449- " must not require any arguments" );
455+ Matcher getterMatcher = getterPattern .matcher (method .getName ());
456+ if ( getterMatcher .matches () ) {
457+ throw new IllegalStateException ("Your getter method, " + method .getName () +
458+ ", annotated with com.marklogic.client.pojo.annotation.Id " +
459+ " must not require any arguments" );
460+ } else if ( method .getName ().startsWith ("set" ) ) {
461+ throw new MarkLogicInternalException ("Your setter method, " + method .getName () +
462+ ", annotated with com.marklogic.client.pojo.annotation.Id " +
463+ "was not found by Jackson for some reason. Please report this to " +
464+ "MarkLogic support." );
465+ } else {
466+ throw new IllegalStateException ("Your setter method, " + method .getName () +
467+ ", annotated with com.marklogic.client.pojo.annotation.Id " +
468+ " must be a proper setter method (beginning with \" set\" )" );
469+ }
450470 }
451471 }
452472 }
0 commit comments