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

Custom Repository returns Optional as return type for T #3125

Closed
jschmied opened this issue Jul 23, 2024 · 1 comment
Closed

Custom Repository returns Optional as return type for T #3125

jschmied opened this issue Jul 23, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@jschmied
Copy link

For migrating existing code I have:

@NoRepositoryBean
public interface MyJpaDao<T, ID> extends Repository<T, ID>, QueryByExampleExecutor<T> {
	T findById(ID id);
}

with DAO:

public interface UserDAO extends MyJpaDao<User, Long> {
      
}

i would expect:
User findById(Long id);

but generated is
Optional<User> findById(Long id);

if I duplicate
User findById(Long id);
in UserDAO, it works as expected. Why?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 23, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 23, 2024
@mp911de mp911de self-assigned this Jul 23, 2024
@mp911de
Copy link
Member

mp911de commented Jul 23, 2024

This is a bug in our QueryExecutionResultHandler component that does not consider the declaring class. It only considers the method signature. Upon resolving T, it resolves against the parameter variable of Repository<T, ID> that resolves to Object instead of considering extends MyJpaDao<User, Long>.

@mp911de mp911de transferred this issue from spring-projects/spring-data-jpa Jul 23, 2024
@mp911de mp911de changed the title Custom Repository returns Optional as return type even if object is defined Custom Repository returns Optional as return type for T Jul 23, 2024
mp911de added a commit that referenced this issue Jul 23, 2024
Simplify assertions.

See #3125
mp911de added a commit that referenced this issue Jul 23, 2024
… method post-processing.

We now consider the declaring class to properly resolve type variable references for the result post-processing of a query method result.

Previously, we attempted to resolve the return type without considering the actual repository class resolving always Object instead of the type parameter.

Closes #3125
mp911de added a commit that referenced this issue Jul 23, 2024
Simplify assertions.

See #3125
mp911de added a commit that referenced this issue Jul 23, 2024
… method post-processing.

We now consider the declaring class to properly resolve type variable references for the result post-processing of a query method result.

Previously, we attempted to resolve the return type without considering the actual repository class resolving always Object instead of the type parameter.

Closes #3125
mp911de added a commit that referenced this issue Jul 23, 2024
Simplify assertions.

See #3125
@mp911de mp911de added this to the 3.2.9 (2023.1.9) milestone Jul 23, 2024
mp911de added a commit that referenced this issue Jul 23, 2024
… method post-processing.

We now consider the declaring class to properly resolve type variable references for the result post-processing of a query method result.

Previously, we attempted to resolve the return type without considering the actual repository class resolving always Object instead of the type parameter.

Closes #3125
mp911de added a commit that referenced this issue Jul 23, 2024
Simplify assertions.

See #3125
mp911de added a commit that referenced this issue Jul 23, 2024
… method post-processing.

We now consider the declaring class to properly resolve type variable references for the result post-processing of a query method result.

Previously, we attempted to resolve the return type without considering the actual repository class resolving always Object instead of the type parameter.

Closes #3125
mp911de added a commit that referenced this issue Jul 23, 2024
Simplify assertions.

See #3125
mp911de added a commit that referenced this issue Jul 23, 2024
… method post-processing.

We now consider the declaring class to properly resolve type variable references for the result post-processing of a query method result.

Previously, we attempted to resolve the return type without considering the actual repository class resolving always Object instead of the type parameter.

Closes #3125
mp911de added a commit that referenced this issue Jul 23, 2024
Simplify assertions.

See #3125
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

3 participants