Pergunta

I have a method:

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;
    }

which returns this:

enter image description here

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

Foi útil?

Solução

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[].

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.

Outras dicas

Not sure it might be something is looking for, but I had similar problem and converted Vector to ArrayList like this:

    final ArrayList<YourClazz> results = new ArrayList<YourClazz>();;
    for ( YourClazzkey : (Vector<YourClazz>) query.getResultList() )
    {
        results.add(key);
    }

i have faced the same problem. and my entity has no one to one or one to many relationship. then also jpql was giving me queryresult as vector of objects. i changed my solution to query to criteria builder. and that worked for me. code snippet is as below:

    CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
    CriteriaQuery<Timetable> criteria = builder.createQuery(Timetable.class);
    Root<Enumeration> root = criteria.from(Timetable.class);
    criteria.where(builder.equal(root.get("id"), id));
    List<Timetable> topics = this.entityManager.createQuery(criteria)   .getResultList();
    return topics;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top