I am implementing a Restful Web Service in java (JAX-RS) using Jesey. I run it on Tomcat v7.0 I use Hibernate to map the data to the database (MySQL). I have a query to fetc
mysql doesn't have TOP, use the ORDER BY and LIMIT clauses at the end of the sql.
I am not sure TOP function is available in mysql but try to use it and share the result. you can write like this: SELECT TOP 2 * FROM Persons
check this link, it will furnish you with more details. enter link description here
I think you are asking for the top 3 Deliverable
s from Task
ordered by ID. You could try something like this:
Edit: Ok I'll take one more stab at this. This should give you the top 3 Deliverable
s ordered by Task.id
taking only the Deliverable
associated to the max(Task.id)
deliverables =
(List<Deliverable>) session.createQuery(
"from Deliverable as d, Task as t
where t.deliverable.id = d.id and
t.id = (select max(t1.id) from Task t1 where t1.deliverable.id = d.id)
and d.project.id= :id
and t.user.username = :name
order by t.id desc")
.setMaxResults(3)
.setLong("id", projectId)
.setString("name", username)
.list();