Skip to content

Allow Optional fields in projection [DATACMNS-1762] #2178

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

Closed
spring-projects-issues opened this issue Jun 30, 2020 · 3 comments
Closed

Allow Optional fields in projection [DATACMNS-1762] #2178

spring-projects-issues opened this issue Jun 30, 2020 · 3 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Wim Deblauwe opened DATACMNS-1762 and commented

Suppose a projection like this:

public interface UserRepository extends CrudRepository<User, UserId> {

  @Query("SELECT u.name as name, u.gender as gender FROM user u") 
  UserInfo findById(UserId id);
}

with:

public interface UserInfo {
  String getName();

  Optional<Gender> getGender();
}

When I currently try this, I get null back instead of Optional.empty() if u.gender is null in the database.

It would be nice if this was possible.

As a "workaround", I define the projection as:

public interface UserInfo {
  String getName();

 @Nullable
 Gender getGender();
}

Affects: 2.2.8 (Moore SR8)

Issue Links:

  • DATACMNS-1836 Native projection stopped working with Java8 datetime

Referenced from: pull request #459

@spring-projects-issues
Copy link
Author

Mark Paluch commented

I moved this ticket to Spring Data Commons as all conversions for query methods happen in Commons

@spring-projects-issues
Copy link
Author

Mark Paluch commented

We could leverage QueryExecutionConverters as we have a similar infrastructure already in place

@spring-projects-issues
Copy link
Author

Wim Deblauwe commented

I started a draft PR at #457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants