title: How to customize the spring-data Repository method names?
body: <p>I've a bunch of entities that use an underscore prefix before the field names and otherwise use camelcase.</p>
  
  <pre><code>@Entity
  public class Customer {
  
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long _id;
  
  
    private String _firstName;
    private String _lastName;
  
    @OneToOne
    private Foo _foo;
  
    // … methods omitted
  }
  </code></pre>
  
  <p>The repository</p>
  
  <pre><code>public interface CustomerRepository extends PagingAndSortingRepository&lt;Customer, Long&gt; {
  
      Iterable&lt;Customer&gt; findByFoo(Foo foo);
  }
  </code></pre>
  
  <p>The corresponding fields in the tables also use this naming scheme:</p>
  
  <pre><code>Customer: _id, _firstName, _lastName, _foo__id
  </code></pre>
  
  <p>Now that I am migrating this project to spring-data, I'm getting many IllegalArgumentExceptions with :</p>
  
  <pre><code>Could not create query metamodel for method
  public abstract java.lang.Iterable  
  
  com.example.repository.CustomerRepository.findByFoo(com.example.model.Foo)!
  
   Unable to locate Attribute  with the given name [foo] on this ManagedType [com.example.model.Customer]
  </code></pre>
  
  <p>I have no need to change hibernate's naming strategy, <strong>but how can I change the query method generation naming algorithm</strong> to map "findByFoo" -> "_foo" on the entity, or in JPQL terms "where x._foo__id = ?1"</p>
  
  <p>I'm using old school xml configuration, and no spring boot.</p>
  
  <hr>
  
  <p><strong>Edit: found this <a href="http://docs.spring.io/spring-data/jpa/docs/current/reference/html/" rel="nofollow">in the docs</a>, which isn't helpful..</strong></p>
  
  <blockquote>
    <p>"As we treat underscore as a reserved character we strongly advise to
    follow standard Java naming conventions (i.e. not using underscores in
    property names but camel case instead)."</p>
  </blockquote>
  
  <p>Perhaps I should refactor the field names, drop the underscore, and then implement a hibernate naming strategy that adds the underscore back in?</p>