jakartaee / data

Data-API
Apache License 2.0
78 stars 26 forks source link

Apply EntityGraph Definition on Query Method #752

Open hantsy opened 1 month ago

hantsy commented 1 month ago

Specification Version

1.0.0-RC1

Bug report

If possible to apply the Entity Graph definitions on Entities to a specific query method in the Repositories? Spring Data JPA provides similar features for developers.

Additional information

For example,

@Entity
@NamedEntityGraph(name="with-comments")
class Post{
   @OneToMany
   Set<Comment> comments
}
interface PostRepository {

    @Find
    @EntityGraph(name="with-comments")
    Post findById(Long id);
}
gavinking commented 1 month ago

This is not in the spec, since it would be a very Java Persistence-specific feature.

Also, the annotations for defining named entity graphs are super-ugly and I'm not a fan of them at all.

We do already have a very similar feature to this in Hibernate Data Repositories, but it uses Hibernate's named fetch profiles stuff, which have a much more elegant annotation-based definition.

gavinking commented 1 month ago

(When we define integration with Jakarta Persistence, this is something we can look at.)

hantsy commented 1 month ago

Yes, it should be part of the JPA integration, but it seems there is no a JPA extended spec jakarta-data-jpa under Jakarta Data.

njr-11 commented 1 month ago

Jakarta Data is only in its 1.0 version. It is not a bug that Jakarta Data does not offer the suggested function. This issue should be an enhancement request, not a bug.