Jihee Kim (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e00400...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYmEwMTJmNTAz...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16975?atlOrigin=eyJpIjoiYmEwMT...
) HHH-16975 (
https://hibernate.atlassian.net/browse/HHH-16975?atlOrigin=eyJpIjoiYmEwMT...
) OrderSpecifier with mysql field function is translated differently (
https://hibernate.atlassian.net/browse/HHH-16975?atlOrigin=eyJpIjoiYmEwMT...
)
Issue Type: Bug Affects Versions: 6.2.3 Assignee: Unassigned Attachments: 스크린샷
2023-07-23 오후 5.23.10.png, 스크린샷 2023-07-23 오후 8.00.51.png Components:
hibernate-core Created: 23/Jul/2023 04:19 AM Priority: Major Reporter: Jihee Kim (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e00400...
)
I used mysql field function in order by clause with Expression.stringTemplate(..) from
querydsl:5.0.0.
After upgrade to hibernate6, I got this erorr
Caused by: org.hibernate.exception.DataException: JDBC exception executing SQL [select
p1_0.id,p1_0.content,p1_0.created_at,p1_0.title,p1_0.updated_at from Post p1_0 where
p1_0.id in(?,?,?) order by field(p1_0.id,(?,?,?))] [Operand should contain 1 column(s)]
[n/a]
Before Hibernate6, it is translated to order by field(p1_0.id,?,?,?).
But, in Hibernate6 there are brackets added in translated query.
I used expression like this below:
val ids = listOf(3L, 1L, 2L)
return Expressions.stringTemplate("FIELD({0}, {1})", id, ids).asc()
I debugged and captured values regarding order by clause in QuerySqmImple.java
(
https://hibernate.atlassian.net/rest/api/3/attachment/content/50520 )
After that, I got to know where the brackets come from.
In MySQLSqlAstTranslator.visitTuple(..), the brackets are added.
I changed Expression to avoid arguments considered as Tuple and it works now.
Expressions.stringTemplate(makeFieldExpressionTemplate(ids.size), makeParams(id,
ids)).asc()
fun makeParams(pathValue: NumberPath<Long>, parmas: List<Long>):
MutableList<*> {
return mutableListOf<Any>()
.apply {
add(pathValue)
addAll(parmas)
}
}
fun makeFieldExpressionTemplate(paramSize: Int): String {
return StringBuilder("FIELD({0}")
.apply {
(1..paramSize).forEach { index ->
append(", {${index}}")
}
append(")")
}.toString()
}
But, I don’t know this is the best way.
Could you check about this?
(
https://hibernate.atlassian.net/browse/HHH-16975#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16975#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100232- sha1:4329f54 )