-
Notifications
You must be signed in to change notification settings - Fork 61
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
Cannot search on 'null' ids in a manyToOne association #50
Comments
could you try specialite=isnull='' ? |
Hi, Thanks for your reply, Like I told you in my previous message, i already tried
On line 109 : As i do not specify any attribute, the attribute property is null. |
It is not supported. You can add a field specialiteId (specialite_id) in UserEntity, then you can query by user.specialiteId=isnull=''. Thanks. |
Hi,
Maybe you could implement that in the library :) Thank you anyway, Cheers, |
You can try this feature https://github.com/perplexhub/rsql-jpa-specification#custom-operator--predicate to customize it. Thanks. |
Hi, I have a similar issue...sorta.
I'm trying to find all the materials without any pictures. So basically a null set of pictures. Is there any way of doing this? On line 109 : This happens because attribute is null if I try something like |
Please try version 5.0.12. I 've added NPE check. |
Hi, Thanks a lot for the quick reply and the fix, I really apreciate it. I tried the new version, and now the NPE moved to It still tries to get an attribute here:
So the execution stops before reaching the custom predicates. |
Please upgrade to v5.0.13. Please refer to io.github.perplexhub.rsql.RSQLJPASupportTest#testCustomPredicateIsNull for details, thanks! String rsql = "city=notAssigned=''";
RSQLCustomPredicate<String> customPredicate = new RSQLCustomPredicate<>(new ComparisonOperator("=notAssigned="), String.class, input -> {
return input.getCriteriaBuilder().isNull(input.getRoot().get("city"));
});
List<User> users = userRepository.findAll(toSpecification(rsql, Arrays.asList(customPredicate))); |
Hi, Thanks a lot for the fix and your help. This should work but I think there's something about the way I'm mapping my entities. I'll figure something out. Thanks again for your help and for this library. It saved me a lot of trouble. :) Best of luck! |
Okay, I managed to find a solution to my problem and I'm gonna post it here in case anyone needs something similar.
I need to filter all parent entities which either have children or don't, and here is my custom predicate:
Now I can find all Parent entities who don't have any Child entities like this:
|
This will not work for deeper relations like parent.children.grandchildren. I think because the JPA spec states that that behavior is undefined (and I see a hibernate exception when I try to do use either the isEmpty or size methods on those). My workaround for now was to use the hibernate specific @formula annotation to count the # of grand children and filter on that. |
the issue can be easily fixed by replacing empty line # 88 with the following code: Line 88 in 4e7cac1 is there any good reason for this code not to be there? |
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [company] on this ManagedType [io.github.perplexhub.rsql.model.Company] |
Hi,
First of all, thanks for your great job on that library. It's very useful.
I encountered one unexpected behavior when trying to use the =isnull= operator on a manyToOne association.
I want to find all users with a NULL specialite.
Here are my JPA entities
My RSQL query looks like that
specialite.id=isnull=
I get no result at all.
I checked the generated SQL request, and there is something wrong
select * from domain_user user0_ inner join domain_specialite specialite1_ on user0_.specialite_id=specialite1_.id where specialite1_.id is null
Because of the where clause on the joined entity, of course there is no specialite with null id in the specialite table
In that particular case, i don't even need any join, the following request would be perfect
select * from domain_user user0_ where user0_.specialite_id is null
To avoid the join, I also tried to not use the 'id' property in the RSQL query
specialite=isnull=
But I got a NullPointerException when you try to resolve the attribute name from the ManyToOne association.
Do you have any workaround to do that ? Maybe i'm doing something wrong with the usage of your library, I hope you could help me :)
Thank you very much,
Cheers,
Cyril
The text was updated successfully, but these errors were encountered: