4

次のように、ネイティブクエリでテーブルから選択しようとしていました:

entityManager.createNativeQuery("SELECT * FROM B_AccountTransaction " +  
"accountTransaction WHERE accountTransaction.depositId = '" + depositId + "'")
                .setFirstResult(firstIndex).setMaxResults(pageSize).getResultList();

が 0の場合firstIndex(内容は関係ありませんpageSize)、Hibernate は次のクエリを作成します。

SELECT
    TOP(?) *  
FROM
    B_AccountTransaction accountTransaction 
WHERE
    accountTransaction.depositId = '10002801130'

これは問題ありfirstIndexませんが、 を 0 以外の値に変更すると、休止状態が次のクエリを作成します。

WITH query AS 
(   SELECT
        inner_query.*,
        ROW_NUMBER() OVER ( ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ 
    FROM
        (   SELECT * as page0_ 
            FROM
                B_AccountTransaction accountTransaction 
            WHERE
            accountTransaction.depositId = '10002801130' 
        ) inner_query 
) 
SELECT
    page0_ 
FROM
    query 
WHERE
    __hibernate_row_nr__ >= ?   -- firstIndex here 
    AND __hibernate_row_nr__ < ?  -- page size here

ただし、このクエリにSELECT * as page0_は有効な SQL Server 構文ではないものが含まれています。

また、次のコードを使用すると、すべて問題ないことに注意してください。

entityManager.createNativeQuery("SELECT accountTransaction.AccountTransactionID as AccountTransactionID, accountTransaction.AccountNo as AccountNo, " +
            "accountTransaction.TransactionNumber as TransactionNumber, accountTransaction.TransactionDate as TransactionDate, accountTransaction.TransactionTime as TransactionTime," +
            "accountTransaction.TransactionTimeStamp as TransactionTimeStamp, accountTransaction.DepositID as DepositID, accountTransaction.BranchCode as BranchCode,  " +
            "accountTransaction.DebitAmount as DebitAmount, accountTransaction.CreditAmount as CreditAmount, accountTransaction.Balance as Balance, accountTransaction.PayerName as PayerName, " +
            "accountTransaction.TransDesc as TransDesc, accountTransaction.ChqNumber as ChqNumber, accountTransaction.TransactionLastRowNumber as TransactionLastRowNumber, accountTransaction.ChqSeri as ChqSeri, " +
            "accountTransaction.DocType as DocType, accountTransaction.TransactionID as TransactionID,  accountTransaction.EffectiveDate as EffectiveDate " +
            " FROM B_AccountTransaction accountTransaction WHERE accountTransaction.depositId = '" + depositId + "'")
            .setFirstResult(firstIndex).setMaxResults(pageSize).getResultList(); 

誰が何が悪いのか教えてもらえますか? これはバグですか、それとも何か間違っていますか?

4

0 に答える 0