Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions