Reputation: 103
*
Query query = session.createQuery("SELECT c.name FROM CompanyEntity c WHERE c.id = :companyId");
query.setInteger("companyId", companyId);
result = query.toString();
Hi.I am fetching name which is String from query. But the result is not returned properly.I am getting the query as a result.Please help.
Thanks
Upvotes: 0
Views: 1809
Reputation: 1366
The Query
object capsulates the formulated query itself, not the result of the query. In order to execute the query and retrieve the result, you have to call
query.list();
which returns a List of the selected properties (i.e. name
in this case).
If your query returns a single result, there is a convenience method:
query.uniqueResult();
And if your query is an update statement, you can execute it without having any result:
query.executeUpdate();
(this last one returns the number of updated entities).
Upvotes: 1