title: Automatically convert a parameter with Spring Data JPA
body: <p>In our entity beans we use a custom ID format which includes a checksum to verify that the ID is actually valid. Ids look like <code>ID827391738979</code>. To make sure that all code uses correct IDs only we created a code wrapper around an ID String:</p>
  
  <pre><code>class ID {
      public ID(String id) {
         // parse and verify ID
      }
  
      public String toString() {
         return id;
      }
  }
  </code></pre>
  
  <p>All code just uses this <code>ID</code> object. However in our entity we have defined the ID as a <code>String</code>:</p>
  
  <pre><code>class SomeEntity {
      @Column
      private String itsID;
  }
  </code></pre>
  
  <p>Now we want to use Spring-Data-JPA to query some object by it's id. So we do:</p>
  
  <pre><code>public SomeEntity findByItsID(ID itsId);
  </code></pre>
  
  <p>Problem is, that now Spring Data JPA tries to assign the ID-typed parameter to the query, while the query of course expects a <code>String</code>.</p>
  
  <p>Is it possible to have Spring Data JPA convert the parameter to the expected type (e.g. by registering a Spring converter) before it is inserted into the query? Or, do we have to let the method take a String like this:</p>
  
  <pre><code>public SomeEntity findByItsId(String itsId);
  </code></pre>
  
  <p>I would rather avoid this, so all code can use the <code>ID</code> class instead of resorting to Strings.</p>