title: How to run a native SQL query in Spring without an entity and a JPA Repository?
body: <p>I am trying to run some native SQL queries in my Spring application. I don´t have an entity or <code>JpaRepository</code> class. I know it's strange, but this is a microservice just to collect two count queries and send it to Kafka.</p>
  
  <p>Well trust me, all I need is these two integers from the queries. I run these code and always returns 0. I can see in the logs that Hikari is connecting to the database, so I don't know what to do. Searched a lot, but all answers involved the <code>@Query</code> solution, which does not work for me.</p>
  
  <pre><code>@Repository
  @AllArgsConstructor
  public class ReportRepository {
  
  
    private final EntityManager em;
  
    public int numberOfAccounts() {
      String sql = "SELECT count(*) FROM account";
      Query query = em.createNativeQuery(sql);
      System.out.println(query.getFirstResult());
      return query.getFirstResult();
    }
  
    public int numberOfSubscriptions() {
      String sql = "SELECT count(*) FROM subscriptions";
      Query query = em.createNativeQuery(sql);
      System.out.println(query.getFirstResult());
      return query.getFirstResult();
    }
  }
  </code></pre>