Skip to content

Verify return type matches the declared query #1184

@spring-projects-issues

Description

@spring-projects-issues

Jacopo Carravieri opened DATAJPA-824 and commented

When using a wrong query, that extracts only a portion of particular object

// Home contains other fields
@Query("SELECT home.id, home.address FROM Home")
List<Home> findAll();

The framework silently casts the result to List<Home>, but actually it turns out to be a List<Object[]>. As soon as a call to get() is made an exception is raised.

I would expect a ClassCastException or something similar thrown by the framework itself. I made some tests, it is possible to make such kind of casts only when the List is first instantiated without the template argument.

// No complain
List list = new ArrayList();
list.add(new Object());
return (List<Home>) list;

Affects: 1.9.1 (Gosling SR1)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions