title: Why does spring-boot-data-jdbc Query Methods require No Args Constructor
body: <p>It seems to me that all Query methods over an entity, using the spring-boot-data-jdbc, require to have a No-Args Constructor?
  Is there a reason why?
  Here is a simple example which gives this exception. Using H2 database</p>
  <blockquote>
  <p>Caused by: org.springframework.beans.BeanInstantiationException:
  Failed to instantiate [com.example.relationaldataaccess.Person]: No
  default constructor found; nested exception is
  java.lang.NoSuchMethodException:
  com.example.relationaldataaccess.Person.()</p>
  </blockquote>
  <p>Typically Person entity -</p>
  <pre><code>import org.springframework.data.annotation.Id;
  
  public class Person {
      
  
      @Id
      private long id;
      private  String firstName;
      private  String lastName;
  
      public Person(String firstName, String lastName) {
          this.firstName = firstName;
          this.lastName = lastName;
      }
  }
  </code></pre>
  <p>And then the repository</p>
  <pre><code>public interface PersonRepository extends CrudRepository&lt;Person, Long&gt;{
  
      @Query(&quot;select * from person where first_name= :firstName&quot;)
      List&lt;Person&gt; findByFirstName(@Param(&quot;firstName&quot;) String firstName);
  
  }
  </code></pre>
  <p>Here is the schema</p>
  <pre><code>create table person (
                          id integer identity not null primary key,
                          first_name varchar(30),
                          last_name varchar(30)
  );
  </code></pre>
  <p>And the Main App</p>
  <pre><code>@SpringBootApplication
  public class Application implements CommandLineRunner {
  
      @Autowired
      private PersonRepository repository;
  
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      @Override
      public void run(String... arg0) throws Exception {
          Person person = new Person(&quot;John&quot;, &quot;Doe&quot;);
          repository.save(person);
          System.out.println(&quot;FIND BY FIRST_NAME -----&gt;&gt; &quot;+ repository.findByFirstName(&quot;John&quot;));
      }
  }
  </code></pre>
  <p>The application.properties file</p>
  <pre><code>spring.jpa.hibernate.ddl-auto=none
  spring.h2.console.enabled=true
  spring.datasource.url=jdbc:h2:mem:persondb
  spring.datasource.driverClassName=org.h2.Driver
  spring.datasource.username=sa
  spring.datasource.password=test
  spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
  logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG
  logging.level.org.springframework.data=INFO
  </code></pre>
  <p>Below is the stack trace of the app-</p>
  <pre><code>java.lang.IllegalStateException: Failed to execute CommandLineRunner
      at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:779) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at com.example.relationaldataaccess.Application.main(Application.java:21) ~[classes/:na]
  Caused by: org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate com.example.relationaldataaccess.Person using constructor NO_CONSTRUCTOR with arguments 
      at org.springframework.data.mapping.model.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:65) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:87) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.data.relational.core.conversion.BasicRelationalConverter.createInstance(BasicRelationalConverter.java:147) ~[spring-data-relational-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.createInstanceInternal(BasicJdbcConverter.java:527) ~[spring-data-jdbc-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.mapRow(BasicJdbcConverter.java:387) ~[spring-data-jdbc-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.data.jdbc.core.convert.BasicJdbcConverter.mapRow(BasicJdbcConverter.java:323) ~[spring-data-jdbc-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.data.jdbc.core.convert.EntityRowMapper.mapRow(EntityRowMapper.java:67) ~[spring-data-jdbc-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy$PostProcessingRowMapper.mapRow(JdbcQueryLookupStrategy.java:152) ~[spring-data-jdbc-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:94) ~[spring-jdbc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:61) ~[spring-jdbc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:679) ~[spring-jdbc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617) ~[spring-jdbc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:669) ~[spring-jdbc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:694) ~[spring-jdbc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.query(NamedParameterJdbcTemplate.java:176) ~[spring-jdbc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.data.jdbc.repository.query.AbstractJdbcQuery.lambda$getQueryExecution$2(AbstractJdbcQuery.java:127) ~[spring-data-jdbc-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.data.jdbc.repository.query.StringBasedJdbcQuery.execute(StringBasedJdbcQuery.java:85) ~[spring-data-jdbc-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor$QueryMethodInvoker.invoke(QueryExecutorMethodInterceptor.java:195) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at com.sun.proxy.$Proxy48.findByFirstName(Unknown Source) ~[na:na]
      at com.example.relationaldataaccess.Application.run(Application.java:28) ~[classes/:na]
      at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      ... 5 common frames omitted
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.relationaldataaccess.Person]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.example.relationaldataaccess.Person.&lt;init&gt;()
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:146) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      at org.springframework.data.mapping.model.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:62) ~[spring-data-commons-2.3.4.RELEASE.jar:2.3.4.RELEASE]
      ... 36 common frames omitted
  Caused by: java.lang.NoSuchMethodException: com.example.relationaldataaccess.Person.&lt;init&gt;()
      at java.base/java.lang.Class.getConstructor0(Class.java:3349) ~[na:na]
      at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553) ~[na:na]
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:139) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
      ... 37 common frames omitted
  
  2020-09-23 19:31:04.053  INFO 29948 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
  2020-09-23 19:31:04.059  INFO 29948 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
  
  Process finished with exit code 1
  </code></pre>