Skip to content

Pageable warnings incosistent or wrong #3660

Closed
@dsuepke-swisscom

Description

@dsuepke-swisscom

Hi,

I have two basically equivalent queries. One of them (findFoo) gives a warning on startup, one (findFoo2) doesn't. The warning seems to be correct, because in our project the query gets very slow.

Specific issues:

  • Either both should give a warning or none. They may be using different techniques in the background, but from a developer standpoint they do the same and should be treated the same.
  • I could not determine whether the warning for findFoo2is missing correctly or incorrectly.:
    • If it is working and thus no warning is given, then why does findFoo not work? Both of them are virtually the same.
    • If, however, the warning is rightfully missing, it needs to be shown

Minimal example:

Log output

 :: Spring Boot ::                (v3.3.5)

2024-11-06T08:53:52.872+01:00  WARN 63873 --- [demo] [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-11-06T08:53:53.107+01:00  WARN 63873 --- [demo] [           main] o.s.d.jpa.repository.query.NamedQuery    : Finder method public abstract org.springframework.data.domain.Page com.example.demo.FooRepository.findFoo(java.lang.String,org.springframework.data.domain.Pageable) is backed by a NamedQuery but contains a Pageable parameter; Sorting delivered via this Pageable will not be applied

FooRepository

@Repository
public interface FooRepository extends JpaRepository<FooEntity, Long>  {

	@Query(name = "FooEntity.findFoo", countName = "FooEntity.findFoo.count", nativeQuery = true)
	Page<FooEntity> findFoo(@Param("foo") String foo, Pageable pageable);

	@Query(value = "SELECT * FROM foo WHERE foo='foo'", countQuery = "SELECT count(*) FROM foo WHERE foo='foo'", nativeQuery = true)
	Page<FooEntity> findFoo2(@Param("foo") String foo, Pageable pageable);
}

FooEntity

@Entity
@Getter
@Setter
@NamedNativeQuery(name = "FooEntity.findFoo", query = "SELECT * FROM foo WHERE foo='foo'")
@NamedNativeQuery(name = "FooEntity.findFoo.count", query = "SELECT count(*) FROM foo WHERE foo='foo'")
public class FooEntity {

	@Id
	@Column
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	private long id;

	@Column
	private String foo;

}

build.gradle

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.3.5'
	id 'io.spring.dependency-management' version '1.1.6'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(21)
	}
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	compileOnly 'org.projectlombok:lombok'
	runtimeOnly 'com.h2database:h2'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
	useJUnitPlatform()
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions