Skip to content

I need some clarification on using a Repository function with projection interface and @EntityGraph #2709

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
SchlauFuchs opened this issue Nov 22, 2022 · 2 comments
Labels
status: feedback-provided Feedback has been provided

Comments

@SchlauFuchs
Copy link

Hi,

not sure if this is a bug or a feature - I did not find any clarification on Stackoverflow or Baeldung and whatever Google brings up in the first 5 pages of results...

So I have some entity model where I am querying an entity with both a m:n and a n:1 relationship, and that one has another n:1 child.
Together a hibernate query results in a query for 100+ fields combined from that entities - of which I need just 8.

This is my find method in the repository:

    @EntityGraph(
        attributePaths = [
            "id",
            "code",
            "status",
            "configurations.id",
            "configurations.attributeKey",
            "configurations.attributeValue",
            "configurations.type.grp",
            "configurations.type.description",
            "configurations.type.curr"
        ]
    )
    fun findByUsers_Id(id: String): List<SkillWithConfigurationsProjection>

SkillWithConfigurationsProjection is an interface following example on Baeldung - Spring Data JPA Projections:

interface SkillWithConfigurationsProjection {
    fun getStatus(): RecordStatus
    fun getId(): Int
    fun getCode(): String
    fun getConfigurations(): List<ConfigWithTypeProjection>
}

I was of the impression that @EntityGraph should hint hibernate which collections need to be eager loaded (that works) and the projection hints which fields should be queried?

I tried with type = EntityGraph.EntityGraphType.LOAD but it did not change the number of columns either.

Where does the problem sit now?

@SchlauFuchs SchlauFuchs changed the title I need some clarification on using a Repository function with projection interface, @Query and @EntityGraph I need some clarification on using a Repository function with projection interface and @EntityGraph Nov 22, 2022
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 22, 2022
@schauder
Copy link
Contributor

Does #1814 answer this question? Can this issue get closed as a dup?

@schauder schauder added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 28, 2022
@SchlauFuchs
Copy link
Author

Yes, I guess so.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided
Projects
None yet
Development

No branches or pull requests

3 participants