I am getting the following error:
Using named parameters for method public static void com.htd.repository.MaterialRepository.uploadMaterialData(java.lang.String,java.math.BigDecimal,java.lang.String,java.math.BigDecimal,java.math.BigDecimal) but parameter 'material_number' not found in annotated query 'INSERT INTO hillcresttooldie VALUES (?,?,?,?,?)'!
I read the documention at: http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html but I am still having issues. I was under the impression JPA created queries for us. I am used to writing out the queries until I cam across this awesome piece of technology.
public interface MaterialRepository extends JpaRepository<Material,Long> {
@Query("INSERT INTO hillcresttooldie VALUES (?,?,?,?,?)")
static void uploadMaterialData(String material_number,BigDecimal material_thickness,String material_size,BigDecimal lb_per_sheet,BigDecimal dollar_per_lb) {
}
}
Trying to use the query in the MaterialResource.java file
//puts materials into map and the key is the material number
materialMap.put(materialValue, material);
MaterialRepository.uploadMaterialData(material.getMaterial_number(), material.getMaterial_thickness(),
material.getMaterial_size(), material.getLb_per_sheet(), material.getDollar_per_lb());
Change your code to
@Query("INSERT INTO hillcresttooldie (material_number,material_thickness,material_size,lb_per_sheet,dollar_per_lb) VALUES (:number, :thickness, :size, :lbPerSheet, :dollarPerLb)")
void uploadMaterialData(String number, BigDecimal thickness, String size, BigDecimal lbPerSheet, BigDecimal dollarPerLb)
try :
public interface MaterialRepository extends JpaRepository<Material,Long> {
@Modifying
@Query(nativeQuery = true,"INSERT INTO hillcresttooldie(material_number,material_thickness,material_size,lb_per_sheet,dollar_per_lb) VALUES (?1,?2,?3,?4,?5)")
static void uploadMaterialData(String material_number,BigDecimal material_thickness,String material_size,BigDecimal lb_per_sheet,BigDecimal dollar_per_lb) {
}
}
public interface MaterialRepository extends JpaRepository<Material,Long> {
@Query("INSERT INTO hillcresttooldie(material_number) VALUES (:material_number)") //....
static void uploadMaterialData(@Param("material_number") String material_number) {
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.