0

「in」式の1つに1000以上のアイテムがある場合に問題が発生する以下のHibernate NamedQueryがあります。(:devices) の ma.deviceId に 1000 個以上のアイテムがあると、java.sql.SQLException: ORA-01795: maximum number of expressions in a list is 1000 が発生します。

私が注意する必要がある唯一の "in" 式は、"and ma.deviceId in (:devices)" です。この NamedQuery を書き直す方法について何か考えがある人はいますか? JPAとHibernateを使用しています。

@NamedQuery(name = "Messages.findMessages", query = " SELECT ma from Messages ma JOIN FETCH ma.messagePayLoadXml mx LEFT OUTER JOIN FETCH ma.messageProperties  mp " +
                  " WHERE ma.customerId = :customerId and ma.time >= :startTime and ma.time <= :endTime " +
                  " and ma.deviceId in (:devices) and  mx.messageType = 'XML' and mx.alerts in " +
                  " ( select mtfm.messageType from MessageTypeFeatureMap mtfm where mtfm.feature in (:featureType) ) " +
                  " and ma.messageKey = mx.messageKey and ( mp.deleted = 0 or mp.deleted is null ) " +
                  " order by ma.time desc " )
4

2 に答える 2

2

2つの方法があります。
1)リストを中間テーブルに保存して実行します
... IN (SELECT ... FROM intermediaryTable)
2)リストをそれぞれ最大1000要素のサブリストに分割し、クエリを次のように記述します
(... IN (subList1) OR ... IN (subList2) ...)

于 2012-08-21T17:37:07.210 に答える