Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hibernate count native query #3244

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,15 @@ class PageSpec extends Specification {
def pageable = Pageable.from(0, 10)
Page<Person> page = personRepository.findByNameLike("A%", pageable)
Page<Person> page2 = crudRepository.findPeople("A%", pageable)
Page<Person> page3 = crudRepository.findPeopleNative("A%", pageable)
Slice<Person> slice = personRepository.queryByNameLike("A%", pageable)

then:"The page is correct"
page.offset == 0
page.pageNumber == 0
page.totalSize == 50
page2.totalSize == page.totalSize
page3.totalSize == page.totalSize
slice.offset == 0
slice.pageNumber == 0
slice.size == 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public interface PersonCrudRepository extends JpaRepository<Person, Long>, Perso
@Transactional
Page<Person> findPeople(String n, Pageable pageable);

@Query(value = "SELECT * FROM person WHERE name LIKE :n",
countQuery = "SELECT COUNT(*) FROM person WHERE name LIKE :n",
nativeQuery = true)
@Transactional
Page<Person> findPeopleNative(String n, Pageable pageable);

@Query("from Person p where p.name = :n")
@Transactional
Person queryByName(String n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ private void processMethodInfo(MethodMatchContext methodMatchContext, MethodMatc
}

builder.member(AnnotationMetadata.VALUE_MEMBER, query);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to populate nativeQuery annotation value later being checked in DefaultStoredQuery.

builder.member(DataMethodQuery.META_MEMBER_NATIVE, element.booleanValue(Query.class,
DataMethodQuery.META_MEMBER_NATIVE).orElse(false));

addQueryDefinition(methodMatchContext,
builder,
Expand Down
Loading