Skip to content
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

IS NOT NULL not possible in correlationExpression #1915

Open
markHervagault opened this issue Jun 24, 2024 · 3 comments
Open

IS NOT NULL not possible in correlationExpression #1915

markHervagault opened this issue Jun 24, 2024 · 3 comments

Comments

@markHervagault
Copy link

markHervagault commented Jun 24, 2024

Description

When I want use ":aOptionnalParam IS NOT NULL" in correlationExpression, I have this compil error :

An error occurred while trying to resolve the condition expression 'providersAffectToLeg.rowid = correlationKey.rowid AND (:transportationModeFilter IS NOT NULL OR transportationMode.rowid = :transportationModeFilter)' of the attribute legSolutions[fr.******.api.dao.projection.ProviderAffectToLegSummaryProjection.getLegSolutions]: Illegal occurence of [:transportationModeFilter] in path chain resolver! Parameters are not allowed as results in mapping. Please use @MappingParameter for this instead!

Steps to reproduce

This correlationExpression not working :

@EntityView(ProvidersAffectToLeg.class)
public interface ProviderAffectToLegSummaryProjection {

    @IdMapping
    Long getRowid();

    ProviderSummaryProjection getProvider();

    @MappingCorrelatedSimple(
            correlationBasis = "rowid",
            correlated = LegSolution.class,
            correlationExpression = "providersAffectToLeg.rowid IN correlationKey " +
                    "AND (:transportationModeFilter IS NULL OR transportationMode.rowid=:transportationModeFilter)",
            fetch = FetchStrategy.JOIN
    )
    List<LegSolutionSummaryProjection> getLegSolutions();
}

This correlationExpression working :

@EntityView(ProvidersAffectToLeg.class)
public interface ProviderAffectToLegSummaryProjection {

    @IdMapping
    Long getRowid();

    ProviderSummaryProjection getProvider();

    @MappingCorrelatedSimple(
            correlationBasis = "rowid",
            correlated = LegSolution.class,
            correlationExpression = "providersAffectToLeg.rowid IN correlationKey " +
                    "AND transportationMode.rowid=:transportationModeFilter",
            fetch = FetchStrategy.JOIN
    )
    List<LegSolutionSummaryProjection> getLegSolutions();
}

It's a bug ?

@beikov
Copy link
Member

beikov commented Jul 5, 2024

Looks like a bug, yes. What are you trying to achieve here? Can't you instead filter against ProvidersAffectToLeg#rowid directly?

@markHervagault
Copy link
Author

I'll take a simpler example to explain my need.
Here is the data model:

CatView:
    kittens: KittenView[]
	
KittenView:
    name: String

And here is the cat I have in my database :

garfield:
	- kittens :
		- name: Sushi
		- name: Mickey
		- name: Oliver

I want to fetch all cats that have kittens with an "e" in their name and fetch only those kittens.
Here's the result I want:

garfield:
	- kittens :
		- name: Mickey
		- name: Oliver

If I use a filter on kittens, I'd get this answer:

garfield:
	- kittens :
		- name: Sushi
		- name: Mickey
		- name: Oliver

That's why I wanted to overwrite the default mapping of my collection
The solution I've found is to let the default mapping on my view, and process the result of my query during my view->dto mapping to remove unwanted kittens. That works too, but I'm fetching kittens for nothing.

Thanks !

@beikov
Copy link
Member

beikov commented Jul 5, 2024

If you want to filter the collection, why not just add a @AttributeFilter(ContainsFilter.class) on KittenView#getName() and activate that via addAttributeFilter("kittens.name", "e")?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants