Custom Query for fetching data from multiple tables in spring Data Jpa

前端 未结 2 761
梦毁少年i
梦毁少年i 2021-02-10 00:49

Entities are following

Product Table

@Entity
public class Product implements Serializable {
/*@Id
@GeneratedValue(strategy = Generation         


        
2条回答
  •  执笔经年
    2021-02-10 01:17

    The way you are doing is not possible because you are assigning the result set to List but the query has some joins, it mean that the result of query is not a Product entity.

    You can try to do a Native query. For example:

    @PersistenceContext
    private EntityManager entityManager;
    
    public List customQuery(int id) {
        Query nativeQuery = entityManager.createNativeQuery(product_ordered).setParameter("id",id);
        return nativeQuery.getResultList();
    }
    

提交回复
热议问题