简体   繁体   中英

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. 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. The stored proc gets called using hibernate session factory and session and ScrollableResultSet. 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.

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. You have to concate a value and use the concatenated value after.

Like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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