Spring JPA存储库查询返回null,但如果我在数据库上运行相同的查询,则返回结果。我无法找到jpa查询返回null的原因。
存储库类:
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
@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;
}
数据库中的表格是:
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")
);
答案 0 :(得分:1)
问题是您只找到一列SELECT EMPLOYEE_FORM_ID
,但尝试填写整个实体RelatorioContribuinteInadimplenteView
,然后框架会丢失,因为它不知道如何填充您的实体。
使用此:SELECT * FROM ...