Discover the Power of Vector Databases in AI: Transforming Data Handling & Insight Generation. Learn how vector embeddings revolutionize search, enhance recommendation systems, enable semantic search, and fuel AI innovation.
Cette bande dessinée didactique a été produite par le Service commun de la Documentation de l'Université de Guyane. Elle s'adresse à un public de doctorants et de chercheurs dans un objectif d'accompagnement à ces nouvelles pratiques scientifiques.
["slug" being an entity attribute]
Spring Data offers an existsBy query method, which we can define in the PostRepository, as follows:
1
2
3
4
5
6
@Repository
public interface PostRepository
extends JpaRepository<Post, Long> {
boolean existsBySlug(String slug);
}
[another] option to emulate existence is using a CASE WHEN EXISTS native SQL query:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Repository
public interface PostRepository
extends JpaRepository<Post, Long> {
@Query(value = """
SELECT
CASE WHEN EXISTS (
SELECT 1
FROM post
WHERE slug = :slug
)
THEN 'true'
ELSE 'false'
END
""",
nativeQuery = true
)
boolean existsBySlugWithCase(@Param("slug") String slug);
}
@Repository
public interface PostRepository extends BaseJpaRepository<Post, Long> {
@Query("""
select p
from Post p
where date(p.createdOn) >= :sinceDate
"""
)
@QueryHints(
@QueryHint(name = AvailableHints.HINT_FETCH_SIZE, value = "25")
)
Stream<Post> streamByCreatedOnSince(@Param("sinceDate") LocalDate sinceDate);
}
The FETCH_SIZE JPA query hint is necessary for PostgreSQL and MySQL to instruct the JDBC Driver to prefetch at most 25 records. Otherwise, the PostgreSQL and MySQL JDBC Drivers would prefetch all the query results prior to traversing the underlying ResultSet.
M. Bechny, F. Sobieczky, J. Zeindl, and L. Ehrlinger. Proceedings of the 33rd International Conference on Scientific and Statistical Database Management, page 214–219. New York, NY, USA, Association for Computing Machinery, (Aug 11, 2021)
M. Bechny, F. Sobieczky, J. Zeindl, and L. Ehrlinger. Proceedings of the 33rd International Conference on Scientific and Statistical Database Management, page 214–219. New York, NY, USA, Association for Computing Machinery, (Aug 11, 2021)
J. Choi, A. Khlif, and E. Epure. Proceedings of the 1st Workshop on NLP for Music and Audio (NLP4MusA), page 23--27. Online, Association for Computational Linguistics, (2020)
J. Choi, A. Khlif, and E. Epure. Proceedings of the 1st Workshop on NLP for Music and Audio (NLP4MusA), page 23--27. Online, Association for Computational Linguistics, (2020)