[JIRA] (HHH-16975) OrderSpecifier with mysql field function is translated differently
by Jihee Kim (JIRA)
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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100232- sha1:4329f54 )
2 years, 8 months
[JIRA] (HHH-16253) [Envers] Schema Validation Failure With Audited (N)Clob Column with Hibernate 6 on H2
by Tristan Lins (JIRA)
Tristan Lins ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-16253 ( https://hibernate.atlassian.net/browse/HHH-16253?atlOrigin=eyJpIjoiOWViZj... )
Re: [Envers] Schema Validation Failure With Audited (N)Clob Column with Hibernate 6 on H2 ( https://hibernate.atlassian.net/browse/HHH-16253?atlOrigin=eyJpIjoiOWViZj... )
I digged into the code and there is something strange.
In both cases, for the Entity#conlusion and Entity_audit#conclusion no Column#setSqlTypeName ( https://github.com/hibernate/hibernate-orm/blob/6.2.6/hibernate-core/src/... ) is set (the setter is called with NULL ).
When the Column#getSqlTypeName ( https://github.com/hibernate/hibernate-orm/blob/6.2.6/hibernate-core/src/... ) getter is called, the sql type is detected using the ddlTypeRegistry ( https://github.com/hibernate/hibernate-orm/blob/6.2.6/hibernate-core/src/... ).
There are different results.
For the Entity class:
getSqlTypeCode( mapping ) = 2005
getColumnSize( dialect, mapping ) = Size(length = 255, scale = 2)
ddlTypeRegistry.getTypeName( getSqlTypeCode( mapping ), getColumnSize( dialect, mapping ) ) = "oid"
But for the Entity_audit class, the ddlTypeRegistry returns varchar:
getSqlTypeCode( mapping ) = 12
getColumnSize( dialect, mapping ) = Size(length = 255, scale = 2)
ddlTypeRegistry.getTypeName( getSqlTypeCode( mapping ), getColumnSize( dialect, mapping ) ) = "varchar(255)"
But the issue is not here, the sqlTypeCode was set before.
When BasicValue#resolveColumn ( https://github.com/hibernate/hibernate-orm/blob/6.2.6/hibernate-core/src/... ) is called, the resolution differs.
For the Entity class, the resolution is:
InferredBasicValueResolution(
jdbcType = ClobTypeDescriptor(CLOB_BINDING)
jdbcMapping = basicType(java.lang.String, 2005)
legacyType = basicType(java.lang.String, 2005)
)
And for the Entity_audit class, the resolution is:
NamedBasicTypeResolution(
basicType = basicType(java.lang.String, 12)
)
I’m still searching why the NamedBasicTypeResolution has the wrong type.
( https://hibernate.atlassian.net/browse/HHH-16253#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16253#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100232- sha1:4329f54 )
2 years, 8 months