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

When using @Query with ResultSetExtractor or RowMapper class a new instance is created on every call #1721

Closed
appreciated opened this issue Jan 22, 2024 · 0 comments
Assignees
Labels
type: bug A general bug

Comments

@appreciated
Copy link

appreciated commented Jan 22, 2024

When using the @Query annotation in Spring Data JDBC, like in the following code snippet:

@Query(value = "SELECT ...", resultSetExtractorClass = ...ResultSetExtractor.class)
List<SomeModel> someSpecialQuery();

It appears that a new instance of the ResultSetExtractor/ RowMapper is recreated on every call to the someSpecialQuery method.

This does not happen if the "ref" Parameter is being used.

Is this intended behaviour?

I'm using spring-boot-starter-data-jdbc:3.1.2

@appreciated appreciated changed the title When using @Query with ResultSetExtractor or a RowMapper a new instance is created on every call When using @Query with ResultSetExtractor or RowMapper class a new instance is created on every call Jan 22, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 22, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 15, 2024
schauder pushed a commit that referenced this issue Apr 23, 2024
Introduce caching for configured RowMapper/ResultSetExtractor.

We now create RowMapper/ResultSetExtractor instances only once if they are considered static configuration.
A configured RowMapper ref/class is always static.
A configured ResultSetExtractor ref/class is static when the extractor does not accept a RowMapper or if the RowMapper is configured.

Default mappers or projection-specific ones require ResultSetExtractor recreation of the ResultSetExtractor is configured as Class.

Reuse TypeInformation as much as possible to avoid Class -> TypeInformation conversion.
Introduce LRU cache for DefaultAggregatePath to avoid PersistentPropertyPath lookups.
Introduce best-effort quoted cache for SqlIdentifier to avoid excessive string object creation.

Closes #1721
Original pull request #1722
schauder added a commit that referenced this issue Apr 23, 2024
Add author tags.

See #1721
Original pull request #1722
schauder added a commit that referenced this issue Apr 23, 2024
Add author tags.

See #1721
Original pull request #1722
schauder added a commit that referenced this issue Apr 24, 2024
See #1721
Original pull request #1722
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants