Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-757

Verify identifier type declared on repository matches the one of the declared domain type

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Do
    • Affects Version/s: 1.11 M1 (Gosling), 1.9.3 (Evans SR3), 1.10.1 (Fowler SR1), 1.11.4 (Gosling SR4), 1.12.1 (Hopper SR1)
    • Fix Version/s: None
    • Component/s: Repositories
    • Labels:
      None
    • Sprint:
      Kay RC1, Kay RC3, Kay GA, Kay SR1, Lovelace M1, Lovelace M2 / M3, Lovelace RC1, Lovelace GA, Lovelace SR1, Moore RC1, Moore RC2, Moore SR1, Moore SR2, Neumann M3, Neumann M4, Neumann RC1

      Description

      Given a Customer entity with id type String and a CustomerRepository with id type Long,
      the repository infrastructure should complain about this "incompatible" id type miss-match.

      @Entity
      public class Customer {
          
          @Id
          String id;
          
          String name;
      }
      
      interface CustomerRepository extends CrudRepository<Customer, Long>{}
      

      Currently the miss-match is silently ignored upon first use.

      One way to fix this would be to check this invariant in org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet().

      public void afterPropertiesSet() {
      	...
      	this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface);
      
      	if(!getEntityInformation().getIdType().equals(repositoryMetadata.getIdType())){
      	    throw new IllegalStateException("Detected id-type mismatch between Entity and Repository! RepositoryInterface: " + getRepositoryInformation().getRepositoryInterface());
      	}
      	...
      	if (!lazyInit) {
      		initAndReturn();
      	}
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mp911de Mark Paluch
              Reporter:
              thomasd Thomas Darimont
              Last updater:
              Mark Paluch
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: