spring-projects / spring-projects/spring-data-relational
Projections require Entity Id field to not throw exception while instantiating
@schauder is already working on this.
Since Jul 21, 2025.
- Dominant language
- Java
- Stars
- 827
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
Description
Issue Description
When creating interface projections that only expose specific fields (closed projections), omitting the entity's @Id field can result in runtime errors during proxy creation, even when the projected fields contain valid non-null data.
Entity
@Data
@Builder
@Table("file")
public class File {
@Id
private Long id;
private String fileId;
private Long uploaderId;
private LocalDateTime uploadDate;
private String fullName;
@Builder.Default
@MappedCollection(idColumn = "file_id")
private Set<Document> documents = new HashSet<>();
}
Projection
public interface FilePreview {
String getFileId();
LocalDateTime getUploadDate();
}
Repository
public interface FileRepository extends CrudRepository<File, Long> {
List<FilePreview> findBy();
}
When invoking findBy an java.lang.IllegalStateException is thrown with message Identifier value must not be null at this point.
Modifying the projection to
public interface FilePreview {
Long getId();
String getFileId();
LocalDateTime getUploadDate();
}
results in the method not throwing exception.
The documentation does not mention anywhere this as an intended behaviour and it's not clear why would it be needed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.