简体   繁体   English

Mysql 5.5与休眠4顺序不一致

[英]Mysql 5.5 with hibernate 4 order by is inconsistent

We are using hibernate 4 and mysql 5.5.x with Innodb as our default engine. 我们正在将Hibernate 4和mysql 5.5.x与Innodb用作默认引擎。 We have a stored proc that returns some rows by joining a view and a temporary MYISAM temp table that gets created inside the stored proc. 我们有一个存储过程,该过程通过连接视图和在存储过程内部创建的临时MYISAM临时表来返回一些行。 The stored proc gets called using hibernate session factory and session and ScrollableResultSet. 使用休眠会话工厂和会话以及ScrollableResultSet调用存储的proc。 It returns a list of object arrays. 它返回对象数组的列表。 Here is the sample query 这是示例查询

SELECT 
col1, col2, col3, col4
FROM view1 v 
JOIN temptable1 t on t.id = v.id
ORDER BY intcol DESC, varcharcol

Here is the problem... For rows that have the same intcol value, the secondary order by on the varcharcol is not working properly, they are being returned in jumbled order. 这里的问题是......对于具有相同intcol值的行,通过在varcharcol不能正常工作的辅助性的,他们正在以混乱的顺序返回。

Example rows being returned 返回示例行

Row1, 10, 'foo'
Row2 , 10, 'bar'
Row3, 10, 'foo'
Row4, 10, 'foo'
Row5, 10, 'bar'

Has anybody encountered a similar problem? 有人遇到过类似的问题吗? Thanks in advance for your answers. 预先感谢您的回答。

Yes, I found out something that can guide you. 是的,我发现了一些可以指导您的东西。

For example, you can't use a variable in order by clause. 例如,您不能在order by子句中使用变量。 You have to concate a value and use the concatenated value after. 您必须连接一个值,然后再使用连接后的值。

Like this: 像这样:

$stid = oci_parse($conn, "SELECT X FROM BOOKS " . $orderby);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM