2

trying to run a native query however I'm getting The column name sb_modelid is not valid. when attempting to map the return object to my model object in java? I have verified all the column names are correct.

1) Why is it referring to my column name as sb_modelid and not sbModelID?

2) Why is not being mapped to my POJO correctly?

Thanks!

Model Object:

package com.dish.wfm.linkingTickets.model.repository;
public class Model {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "sbModelID")
    private Long sbModelId;

    @Column(name = "modelID")
    private String modelID;

    @Column(name = "serialNumber")
    private String serialNumber;

    @Column(name = "serviceContractNumber")
    private String serviceContractNumber;

}

Repo:

@Repository
public interface SBModelRepo extends JpaRepository<Model, Long> {
    @Query(value = "select m.sbModelID, m.modelID, m.serialNumber, m.serviceContractNumber from sb.Model m where m.modelID = ?1 and m.serialNumber = ?2", nativeQuery = true)
    Model findTopByModelIDAndSerialNumber(String modelID, String serialNumber);
}
Billy
  • 1,049
  • 3
  • 14
  • 23
  • Are you using hibernate as your JPA implementation - if so what version ? This post might be describing the same issue you are facing: https://stackoverflow.com/questions/25283198/spring-boot-jpa-column-name-annotation-ignored – 0xadecimal Oct 07 '19 at 18:19
  • 1
    Is there an ```@Entity``` annotation in your code? – 윤현구 Oct 08 '19 at 02:32
  • And please check it about ```jpa.hibernate.ddl-auto``` on your config file : yml or properties file – 윤현구 Oct 08 '19 at 02:34

0 Answers0