Hibernate escaping “:” character
up vote
0
down vote
favorite
I've found some posts here and some answers. I've tried every each of them with bad results. I don't want to use stored procedures.
I'm using Hibernate in Java, with MySQL. Some of my query string is:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit := ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank := @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
Some people said a solution is using /*'*/:=/*'*/
inside the query (post), but it doesn't work for me:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit /*'*/:=/*'*/ ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank /*'*/:=/*'*/ @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
I'm despereted!
Any idea, please? I'd be so grateful!
Thanks!
mysql hibernate
add a comment |
up vote
0
down vote
favorite
I've found some posts here and some answers. I've tried every each of them with bad results. I don't want to use stored procedures.
I'm using Hibernate in Java, with MySQL. Some of my query string is:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit := ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank := @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
Some people said a solution is using /*'*/:=/*'*/
inside the query (post), but it doesn't work for me:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit /*'*/:=/*'*/ ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank /*'*/:=/*'*/ @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
I'm despereted!
Any idea, please? I'd be so grateful!
Thanks!
mysql hibernate
What is the logic behind your query?
– Tim Biegeleisen
2 days ago
Don't think about that, is just a example. It's not the full query, only pieces of code with the ":=" characters.
– Ommadawn
2 days ago
Well I'm thinking about it. In particular, I'm thinking you should avoid using session variables with Hibernate, and maybe I can give you a workaround.
– Tim Biegeleisen
2 days ago
Ok, I'll edit the query and put the original example.
– Ommadawn
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've found some posts here and some answers. I've tried every each of them with bad results. I don't want to use stored procedures.
I'm using Hibernate in Java, with MySQL. Some of my query string is:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit := ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank := @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
Some people said a solution is using /*'*/:=/*'*/
inside the query (post), but it doesn't work for me:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit /*'*/:=/*'*/ ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank /*'*/:=/*'*/ @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
I'm despereted!
Any idea, please? I'd be so grateful!
Thanks!
mysql hibernate
I've found some posts here and some answers. I've tried every each of them with bad results. I don't want to use stored procedures.
I'm using Hibernate in Java, with MySQL. Some of my query string is:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit := ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank := @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
Some people said a solution is using /*'*/:=/*'*/
inside the query (post), but it doesn't work for me:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit /*'*/:=/*'*/ ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank /*'*/:=/*'*/ @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
I'm despereted!
Any idea, please? I'd be so grateful!
Thanks!
mysql hibernate
mysql hibernate
edited yesterday
asked 2 days ago
Ommadawn
165115
165115
What is the logic behind your query?
– Tim Biegeleisen
2 days ago
Don't think about that, is just a example. It's not the full query, only pieces of code with the ":=" characters.
– Ommadawn
2 days ago
Well I'm thinking about it. In particular, I'm thinking you should avoid using session variables with Hibernate, and maybe I can give you a workaround.
– Tim Biegeleisen
2 days ago
Ok, I'll edit the query and put the original example.
– Ommadawn
2 days ago
add a comment |
What is the logic behind your query?
– Tim Biegeleisen
2 days ago
Don't think about that, is just a example. It's not the full query, only pieces of code with the ":=" characters.
– Ommadawn
2 days ago
Well I'm thinking about it. In particular, I'm thinking you should avoid using session variables with Hibernate, and maybe I can give you a workaround.
– Tim Biegeleisen
2 days ago
Ok, I'll edit the query and put the original example.
– Ommadawn
2 days ago
What is the logic behind your query?
– Tim Biegeleisen
2 days ago
What is the logic behind your query?
– Tim Biegeleisen
2 days ago
Don't think about that, is just a example. It's not the full query, only pieces of code with the ":=" characters.
– Ommadawn
2 days ago
Don't think about that, is just a example. It's not the full query, only pieces of code with the ":=" characters.
– Ommadawn
2 days ago
Well I'm thinking about it. In particular, I'm thinking you should avoid using session variables with Hibernate, and maybe I can give you a workaround.
– Tim Biegeleisen
2 days ago
Well I'm thinking about it. In particular, I'm thinking you should avoid using session variables with Hibernate, and maybe I can give you a workaround.
– Tim Biegeleisen
2 days ago
Ok, I'll edit the query and put the original example.
– Ommadawn
2 days ago
Ok, I'll edit the query and put the original example.
– Ommadawn
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Finally I could fix it using double backslash inside the Java query code:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit \:= ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank \:= @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Finally I could fix it using double backslash inside the Java query code:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit \:= ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank \:= @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
add a comment |
up vote
0
down vote
accepted
Finally I could fix it using double backslash inside the Java query code:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit \:= ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank \:= @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Finally I could fix it using double backslash inside the Java query code:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit \:= ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank \:= @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
Finally I could fix it using double backslash inside the Java query code:
SET @rank = 0;
SET @limit = 0.1;
SELECT (@limit \:= ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
SELECT IF((@rank \:= @rank + 1) <= @limit, true, false) AS 'popularity', p.id
FROM Pics AS p
ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;
answered yesterday
Ommadawn
165115
165115
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222466%2fhibernate-escaping-character%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What is the logic behind your query?
– Tim Biegeleisen
2 days ago
Don't think about that, is just a example. It's not the full query, only pieces of code with the ":=" characters.
– Ommadawn
2 days ago
Well I'm thinking about it. In particular, I'm thinking you should avoid using session variables with Hibernate, and maybe I can give you a workaround.
– Tim Biegeleisen
2 days ago
Ok, I'll edit the query and put the original example.
– Ommadawn
2 days ago