Enum value giving jdbcMapping error while using query in springboot

My requirement is to find entry by patientId, patientType and DeletedAt, DeletedBy, DeletedByUserType these three should be null

I used this query but it is not able to map patientType which is a ENUM

Error

"An error occurred during data insertion in An error occurred during data insertion in Cannot invoke \"org.hibernate.metamodel.mapping.JdbcMapping.getJdbcValueBinder()\" because \"jdbcMapping\" is null"

Query

 @Transactional
 @Query(value="SELECT * FROM tb_patient o WHERE o.patientId = :patientId AND o.patientType = :patientType AND o.deletedAt Is Null AND o.deletedBy Is Null AND o.deletedByUserType Is Null ", nativeQuery = true)

    List<PatientInsurance> findCustomQuery(@Param("patientId")String patientId, @Param("patientType")PatientTypeEnum patientType);
    

Enum Class

public enum PatientTypeEnum {
    OPG("OPG"),
    OTS("OTS");
    private final String code;

    PatientTypeEnum(String code) {
        this.code = code;
    }
    public String getCode() {
        return code;
    }
}

Entity Class

private class InsuranceEntity{
   @Enumerated(EnumType.STRING)
    @Column(name = "patientType", length = 3, nullable = false)
    private PatientTypeEnum patientType;
}

  • Atleast give reason for downvote , or any related post

    – 

  • You can’t use the enum in a native query. Try to use jpql or the name of the enum as string.

    – 




  • @Jens how and what changes are required can you please highlight

    – 

  • Remove native=true

    – 

  • 1

    BTW: I would always recommend to not use native queries in spring environment.

    – 

Maybe try this on the @Query

o.patientType=:#{#patientType?.code()}

instead of o.patientType = :patientType

Reference: Can I use enum parameter into JpaRepository nativeQuery?

Leave a Comment