therealscifi
therealscifi

Reputation: 382

Why does Hibernate JPA lose the column names when queried?

When I query Hibernate with a:

"select a from Account a", JAXRS gives me column names in my JSON, but when I execute this query:

"select a.firstName, a.lastName from Account a" the JSON simply contains the data without the column names.

For instance:

{ firstName: "Simon" }

becomes:

{ "Simon" }

Upvotes: 0

Views: 263

Answers (1)

JB Nizet
JB Nizet

Reputation: 691755

select a from Account a

is a JPQL query that returns a List<Account>. This list is thus serialized to JSON as an array of objects.

On the other hand,

select a.firstName, a.lastName from Account a

is a JPQL query that returns a List<Object[]>. This list is thus serialized to JSON as an array of arrays.

And finally,

select a.firstName from Account a

is a JPQL query that returns a List<String>. This list is thus serialized to JSON as an array of strings.

Upvotes: 1

Related Questions