Lucy
Lucy

Reputation: 491

createSQLQuery in Hibernate

I have the following code:

String SQL_QUERY ="Select abstractDesc from article";
Query query = session.createSQLQuery(SQL_QUERY);
Object [] amount = (Object []) query.uniqueResult(); 
out.println("mean amount: " + amount[0]);

but I get the following error:

Hibernate: Select abstractDesc from article query did not return a unique result: 10

How can I solve this to have the query executed and print the result properly?

Upvotes: 0

Views: 2339

Answers (1)

Arion
Arion

Reputation: 31239

As you are using uniqueResult(), you are telling Hibernate that you are expecting only a single value.

Check your database or replace uniqueResult() with [list()]1 to see what you get back.

Upvotes: 2

Related Questions