TypedQuery< x>返回Object []的向量,而不是x类型对象的列表 [英] TypedQuery<x> returns vector of Object[] instead of list of x-type object

查看:74
本文介绍了TypedQuery< x>返回Object []的向量,而不是x类型对象的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法:

public List<Timetable> getTimetableTableForRegion(String id) {
        List<Timetable> timetables;
        TypedQuery<Timetable> query = em_read.createQuery("SELECT ..stuff.. where R.id = :id", Timetable.class).setParameter("id", Long.parseLong(id));
        timetables = query.getResultList();

        return timetables;
    }

返回以下内容:

那么,为了返回Timetable的列表,我想念什么?

so, what am I missing in order to return a list of Timetable's?

推荐答案

好,因此,我的JPQL的..stuff..部分包含与其他表的内部联接.即使在SELECT中,也仅从一个表中选择了字段,并将其用作类型-Timetable,Eclipslink无法确定此字段是否属于该实体,因此无法返回已定义实体的列表,而不会返回Object[]的列表

ok, so, ..stuff.. part of my JPQL contained an inner join to other table. Even through in SELECT there were selected fields just from one table, which was used as type - Timetable, Eclipslink was unable to determine if this fields are part of that entity and instead of returning list of defined entity returned list of Object[].

因此,结论是:使用@ OneToMany/@ ManyToOne映射(或平面表设计)并仅查询JPQL中的一个表,以能够对返回的实体进行类型化.

So in conclusion: Use @OneToMany/@ManyToOne mappings (or flat table design) and query just for ONE table in your JPQL to be able to typize returned entities.

这篇关于TypedQuery&lt; x&gt;返回Object []的向量,而不是x类型对象的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆