1

Spring JPA repository query is returning null but if I run the same query on database it returns the results. I couldn't find the reason why jpa query is returning null.

Repository Class:

public interface RelatorioContribuinteInadimplenteRepository extends  JpaRepository<RelatorioContribuinteInadimplenteView, String>{

  @Transactional(readOnly = true, timeout = 600)
  @Query(value = " SELECT EMPLOYEE_FORM_ID"
        + " FROM EMPLOYEE_FORM"
        + " WHERE FORM_TYPE_CD = ?1 ", nativeQuery = true)

List<RelatorioContribuinteInadimplenteView> findByFilters(String code);

  }

Entity class:

  @Entity
  @Table(name = "EMPLOYEE_FORM")
  public class RelatorioContribuinteInadimplenteView implements Serializable         {
   private static final long serialVersionUID = 1L;

   @Column(name = "FORM_TYPE_CD")
   @Getter @Setter
   private String regiaoTributaria;

   @Id
    @Column(name = "EMPLOYEE_FORM_ID")
    @Getter @Setter
   private String ordem;



  }

Table in database is:

 CREATE TABLE EMPLOYEE_FORM 
   (    "EMPLOYEE_FORM_ID" CHAR(12 BYTE) NOT NULL ENABLE, 
      "FORM_TYPE_CD" CHAR(12 BYTE) DEFAULT ' ' NOT NULL ENABLE, 
       PRIMARY KEY ("TAX_FORM_ID")
       );
3
  • have you tried just sql query to the database? are you sure that the expected data exists? Commented May 30, 2018 at 14:57
  • What is the code you are using in the query? It has to be 12 characters long as you use a `CHAR(12) as a datatype. So you need te prefix is with spaces to make it 12 long. Else it will never match. Commented May 31, 2018 at 7:11
  • As I have mentioned, the sql returns the expected data in database. I am using above entity for mapping the table fields Commented May 31, 2018 at 8:22

1 Answer 1

1

The problem is you find only one column SELECT EMPLOYEE_FORM_ID, but attempt to fill in the whole entity RelatorioContribuinteInadimplenteView, then the framework gets lost because it does not know how to fill your entity.

Use this: SELECT * FROM ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.