I need to get an equivalent to this SQL that can be run using Hibernate. It doesn’t work as is due to special characters like @.
SELECT place from (select @curRow := @curRow + 1 AS place, time, id FROM `testing`.`competitor` JOIN (SELECT @curRow := 0) r order by time) competitorList where competitorList.id=4;
My application is managing results of running competitions. The above query is selecting for a specific competitor, it’s place based on his/her overall time.
For simplicity I’ll only list the COMPETITOR table structure (only the relevant fields). My actual query involves a few joins, but they are not relevant for the question:
CREATE TABLE competitor {
id INT,
name VARCHAR,
time INT
}
Note that competitors are not already ordered by time, thus, the ID cannot be used as rank. As well, it is possible to have two competitors with the same overall time.
Any idea how I could make this work with Hibernate?
I couldn’t find any way to do this, so I had to change the way I’m calculating the position. I’m now taking the top results and am creating the ladder in Java, rather than in the SQL query.