Home » Java » Spring Data JPA SpEL support does not work in select & left join

Spring Data JPA SpEL support does not work in select & left join

Posted by: admin September 26, 2018 Leave a comment

Questions:

I faced a problem in using entity name as a parameter in repository. SpEL support does not work in select & left join. I want to do select item from an entity and replace it into another entity like:

@Query("SELECT "
            + "    new com.testing.hello.model.inventory.InventoryValue(t.product, "
            + "t.location, "
            + "coalesce(:#{#inventoryCogs.beginCogs}, 0), "
            + "(coalesce(:#{#inventoryCogs.beginCogs}, 0) * t.product.unitContainLarge) "
            + ") "
            + "FROM "
            + "TransactionRecap t "
            + "LEFT JOIN :#{#inventoryCogs} ON :#{#inventoryCogs.product} = t.product "
            + "WHERE (t.transactionDate <= :endDate)"
            + "GROUP BY "
            + "t.product, t.location")
    InventoryValue findInventoriesValue(@Param("inventoryCogs") InventoryCOGS inventoryCogs, @Param("endDate") Date endDate);

When I run my program, it occurs errors because of the left join and the select :#{#inventoryCogs.beginCogs}

Answers: