JPQL: Receiving a Collection in a Constructor Expression

前端 未结 3 1112
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 10:34

I\'m using JPQL and want to receive some normal parameters and a collection in a Constructor Expression to directly create the DTO-objects. But if the Collection is empty, I

3条回答
  •  时光说笑
    2020-12-09 11:34

    I had a similar problem and tried "Object" in DTO constructor as James suggested, but a child object is passed in and it seems that it is only the first child instead of the expected List/Array of children.

    I ended up with a "normal" query creating all the DTOs in a for loop.

    TypedQuery query = em.createQuery("SELECT p FROM Parent p", Parent class);
            List list = query.getResultList();
            List result = new ArrayList<>();
            for (Parent p : list)
            {
                DTO dto = new DTO();
                //set dto props and fill collection
                result.add(obj);
            }
            return result;
    

提交回复
热议问题