question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

Support Subquery Exists

See original GitHub issue
image Currently kotlin-jdsl does not support the CriteriaBuilder.exists method. An implementation of this method is required.

A function like below code should be implemented in jdsl.

think about what kind of appearance is suitable for jdsl.

โ€“ korean ํ˜„์žฌ kotlin-jdsl ์€ CriteriaBuilder.exists ๋ฉ”์†Œ๋“œ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด ๋ฉ”์†Œ๋“œ์˜ ๊ตฌํ˜„์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ์ฝ”๋“œ์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์ด jdsl์— ๊ตฌํ˜„ ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์–ด๋–ค ๋ชจ์Šต์ด jdsl ์— ์ ํ•ฉํ•œ์ง€ ๊ฐ™์ด ๊ณ ๋ฏผํ•ด๋ณด์•˜์œผ๋ฉด ํ•ฉ๋‹ˆ๋‹ค.

@shouwn @huisam @pickmoment

CriteriaBuilder builder = entityManager.getCriteriaBuilder();
 
CriteriaQuery<Post> query = builder.createQuery(Post.class);
Root<Post> p = query.from(Post.class);
 
ParameterExpression<Integer> minScore = builder.parameter(Integer.class);
Subquery<Integer> subQuery = query.subquery(Integer.class);
Root<PostComment> pc = subQuery.from(PostComment.class);
subQuery
    .select(builder.literal(1))
    .where(
        builder.equal(pc.get(PostComment_.POST), p),
        builder.gt(pc.get(PostComment_.SCORE), minScore)
    );
 
query.where(builder.exists(subQuery));
 
List<Post> posts = entityManager.createQuery(query)
    .setParameter(minScore, 10)
    .getResultList();

generated SQL

SELECT
    p.id AS id1_0_,
    p.title AS title2_0_
FROM post p
WHERE EXISTS (
    SELECT 1
    FROM post_comment pc
    WHERE
        pc.post_id=p.id AND
        pc.score > ?
)
ORDER BY p.id

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
shouwncommented, Nov 9, 2022

@kihwankim @cj848 2.0.7.RELEASE is released

2reactions
shouwncommented, Oct 31, 2022

@cj848 where(exists(subquery))ํ˜•ํƒœ๊ฐ€ ๋”ฑ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๐Ÿ‘

โ€” english where(exists(subquery)) is the best form.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL EXISTS Operator - W3Schools
The EXISTS operator is used to test for the existence of any record in a subquery. The EXISTS operator returns TRUE if the...
Read more >
SQL: EXISTS Condition - TechOnTheNet
The SQL EXISTS condition is used in combination with a subquery and is considered to be met, if the subquery returns at least...
Read more >
SQL EXISTS operator - w3resource
The EXISTS checks the existence of a result of a Subquery. The EXISTS subquery tests whether a subquery fetches at least one row....
Read more >
Subqueries and EXISTS - MariaDB Knowledge Base
Subqueries using the EXISTS keyword will return true if the subquery returns any rows. Conversely, subqueries using NOT EXISTS will return true only...
Read more >
Using EXISTS and NOT EXISTS with correlated subqueries
EXISTS and NOT EXISTS are used with a subquery in WHERE clause to examine if the result the subquery returns is TRUE or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found