2016-04-22 6 views
0

WHERE句の「複合値」を持つクエリの実装としてEclipseLinkを持つJPA 2.1で声明を:私が達成したい何JPA - 私は、次の(この例では:MySQLの)を実現したい

select * 
from account 
where (mailing_zip_code, id) > (56237, 275) 
order by mailing_zip_code asc, id asc 
limit 10; 

クエリ内のオフセットを使用しない無限スクロールのためのシークメソッドの実装です。 where句に焦点を当てて、私はこの構造の正しい名前を見つけることができません。いくつかの場所では「合成値」と呼ばれますが、この名前で結果を見つけることはできませんが、SQL-92標準に準拠しているようです。

この文はフィルタパラメータによって拡張されるため、JPA基準APIを使用して構築することは当然です。

私はAPIをしばらく検索しましたが、これが可能なのかどうか、誰にどのようにできるのですか?

答えて

0

select * 
from account 
where (mailing_zip_code, id) > (56237, 275) 
order by mailing_zip_code asc, id asc 
limit 10; 

を書くためだけの短い道であることを認識した後

select * 
from account 
where mailing_zip_code > '56237' 
or (mailing_zip_code = '56237' AND id > 276) 
order by mailing_zip_code asc, id asc 
limit 10; 

基準クエリはなかったこと、ハードすべて(追加だけで述語)の後:

if (null != startId) { 
    Predicate dateGreater = cb.greaterThan(entity.get(sortBy), startValue); 

    Predicate dateEqual = cb.equal(entity.get(sortBy), startValue); 
    Predicate idGreater = cb.greaterThan(entity.get("id"), startId); 
    Predicate dateEqualAndIdGreater = cb.and(dateEqual, idGreater); 

    cb.or(dateGreater, dateEqualAndIdGreater); 
} 

より良い方法があれば、私はそれについて学ぶことが非常にうれしいです。

+0

長いクエリを使用すると、mailing_zip_codeが '56237'より大きく、id値が276未満の結果が得られます。 '(mailing_zip_code、id)>(x、y)'の意味は?私はそれが驚くべきことであることを発見 – carbontax

+0

「276未満」の部分はどこから手に入りますか?私はtypo(275の代わりに276)を見ますが、このステートメントは明らかに 'id> 276 'と言います。私はMarkus Winandのこのプレゼンテーションでこの声明を見つけました:http://image.slidesharecdn.com/paginationdonethepostgresqlwayv2-130530141009-phpapp02/95/pagination-done-the-right-way-23-638.jpg?cb=1403756206(http ://de.slideshare.net/MarkusWinand/p2d2-pagination-done-the-postgresql-way?ref = http://use-the-index-luke.com/blog/2013-07/pagination-done-the -postgresql-way) – javahippie

+0

Typoを除いて、mailing_zip_codeが '56237'(任意の値のidを含む)より大きく、すべてのアカウントのセットがmailing_zip_code = '56237 'id> 276 – carbontax

関連する問題