web-dev-qa-db-ja.com

パラメーターバインディングの名前は、nullまたは空であってはなりません!名前付きパラメーターの場合、Javaバージョンのクエリメソッドパラメーターに@Paramを使用する必要があります

これは以前に投稿されましたが、私の問題は少し異なります。これは問題のJPQLクエリです。

@Query("SELECT NEW com.htd.domain.ShopOrder(po.id, po.po_number, "
            + "po.due_date, po_part.id, po_part.part_quantity, "
            + "part.id, part.part_number, part.part_description, "
            + "part.plasma_hrs_per_part, part.Grind_hrs_per_part, "
            + "part.mill_hrs_per_part, part.brakepress_hrs_per_part) "
            + "FROM Po po "
            + "LEFT JOIN po.partList po_part "
            + "LEFT JOIN po_part.part part "
            + "LEFT JOIN po_part.part where po.id = :id")
    List<ShopOrder> getShopOrder(long id);

今、私はやろうとしました:

@Query("SELECT NEW com.htd.domain.ShopOrder(po.id, po.po_number, "
            + "po.due_date, po_part.id, po_part.part_quantity, "
            + "part.id, part.part_number, part.part_description, "
            + "part.plasma_hrs_per_part, part.Grind_hrs_per_part, "
            + "part.mill_hrs_per_part, part.brakepress_hrs_per_part) "
            + "FROM Po po "
            + "LEFT JOIN po.partList po_part "
            + "LEFT JOIN po_part.part part "
            + "LEFT JOIN po_part.part where po.id = :id")
    List<ShopOrder> getShopOrder(@Param(value="id"));

しかし、これは私に次のような警告を与えます:

    [ERROR] org.Apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].  
 [dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in 
 context with path [] threw exception [Request processing failed; nested   
 exception is org.springframework.dao.InvalidDataAccessApiUsageException: 
 Name for parameter binding must not be null or empty! For named parameters 
 you need to use @Param for query method parameters on Java versions < 8.; 
 nested exception is Java.lang.IllegalArgumentException: Name for parameter 
 binding must not be null or empty! For named parameters you need to use 
 @Param for query method parameters on Java versions < 8.] with root cause
Java.lang.IllegalArgumentException: Name for parameter binding must not be 
null or empty! For named parameters you need to use @Param for query method   
parameters on Java versions < 8.

クエリを実行しているメソッドは次のとおりです。

 /**
     * Generate Shop Orders.
     */
    @RequestMapping(value = "/generateShopOrder/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
    @Timed
    public void generate(@PathVariable Long id) throws URISyntaxException {
        System.out.println("po id to generate = " + id);

        List<ShopOrder> shopOrders = po_partRepository.getShopOrder(id);

        for(ShopOrder order: shopOrders) {
            System.out.println("-------Printing Shop Orders" + order);
        }

    }

助言?

- - - - - - 更新 - - - - - - - -

これで問題が解決したようです:

@Query("SELECT NEW com.htd.domain.ShopOrder(po.id, po.po_number, "
            + "po.due_date, po_part.id, po_part.part_quantity, "
            + "part.id, part.part_number, part.part_description, "
            + "part.plasma_hrs_per_part, part.Grind_hrs_per_part, "
            + "part.mill_hrs_per_part, part.brakepress_hrs_per_part) "
            + "FROM Po po "
            + "LEFT JOIN po.partList po_part "
            + "LEFT JOIN po_part.part part "
            + "LEFT JOIN po_part.part where po.id = ?1")
    List<ShopOrder> getShopOrder(Long id);

しかし、今私は言っているエラーが発生しています:

[ERROR] org.Apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].
[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in 
context with path [] threw exception [Request processing failed; nested 
exception is org.springframework.dao.InvalidDataAccessApiUsageException: 
org.hibernate.QueryException: could not instantiate class 
[com.htd.domain.ShopOrder] from Tuple; nested exception is 
Java.lang.IllegalArgumentException: org.hibernate.QueryException: could not 
instantiate class [com.htd.domain.ShopOrder] from Tuple] with root cause
Java.lang.IllegalArgumentException: null

ShopOrder:

public ShopOrder(long po_id, String po_number, LocalDate po_due_date,
    long po_part_id, int part_quantity, long part_id,
    String part_number, String part_decription, BigDecimal plasma_hrs,
    BigDecimal Grind_hours, BigDecimal mill_hrs,
    BigDecimal breakpress_hrs) {

        this.po_id = po_id;
        this.po_number = po_number;
        this.po_due_date = po_due_date;
        this.po_part_id = po_part_id;
        this.part_quantity = part_quantity;
        this.part_id = part_id;
        this.part_number = part_number;
        this.part_decription = part_decription;
        this.plasma_hrs = plasma_hrs;
        this.Grind_hours = Grind_hours;
        this.mill_hrs = mill_hrs;
        this.breakpress_hrs = breakpress_hrs;

    }

Database tables

23
Drew1208

:po.id =:idを使用する代わりに、単に?1 ....を使用します。

@Query("SELECT NEW com.htd.domain.ShopOrder(po.id, po.po_number, "
             + "po.due_date, po_part.id, po_part.part_quantity, "
            + "part.id, part.part_number, part.part_description, "
            + "part.plasma_hrs_per_part, part.Grind_hrs_per_part, "
            + "part.mill_hrs_per_part, part.brakepress_hrs_per_part) "
            + "FROM Po po "
            + "LEFT JOIN po.partList po_part "
            + "LEFT JOIN po_part.part part "
            + "LEFT JOIN po_part.part where po.id = ?1")
    List<ShopOrder> getShopOrder(Long id);
19
Drew1208

このパラメーターの説明を試してください。

List<ShopOrder> getShopOrder(@Param("id") long id);
64
RoutesMaps.com