rsql-jpa-specification
rsql-jpa-specification copied to clipboard
Add =isEmpty= to QueryDSL support
Want to filter Nested Collection (OneToMany) isEmpty or field
Example is
{
{
"id":"252355",
"deleted":false
"properties":[
{"id":"sgdegegwe",
"deleted": false
}
]
}
},{
{
"id":"252555",
"deleted":false
"properties":[
]
}
,{
{
"id":"252555",
"deleted":false
"properties":[
{"id":"sgdegegwe",
"deleted": true
}
]
}
}
rsql Query is then
filter=deleted==false;(properties.deleted==false , properties=isEmpty='')
Response will be
{
{
"id":"252355",
"deleted":false
"properties":[
{"id":"sgdegegwe",
"deleted": false
}
]
}
},{
{
"id":"252555",
"deleted":false
"properties":[
]
}
}
Do i have to implement Custom Operator or how it can easy work?
Could you provide your expected querydsl query?
Do you mean this line of my request filter=deleted==false;(properties.deleted==false , properties=isEmpty='')
with =isEmpty='' ? Or something else?
I mean in querydsl syntax.
I reading some pages linked below. After that it should be a left join, where i can check if the join have no result or when is something there with condition. https://stackoverflow.com/questions/51031350/jpa-hibernate-querydsl-left-join-with-condition-doesnt-work https://stackoverflow.com/questions/18190858/querydsl-cross-join-returns-zero-elements https://stackoverflow.com/questions/28568308/filter-with-spring-data-and-querydsl-on-nullable-reference-attribute https://stackoverflow.com/questions/26876740/difficult-with-a-query-and-join
Data Model Element
@OneToMany Element->ElementProperties
After this the query should be
query.from(element)
.leftJoin(element.properties,elementProperties)
.fetchJoin()
.where(elementProperties.deleted.eq(false)).or(elementProperties.id..isNull(()))).fetch();
or some other
query.from(element)
.leftJoin(element.properties,elementProperties)
.fetchJoin()
.where(elementProperties.id.eq("abcde")).or(elementProperties.id..isNull(()))).fetch();
SQL
Select *
from Element el left join ElementProperties eP on eP.element_id = el.id
where eP.deleted == false or eP.element_id IS NULL
With syntax
elementProperties.deleted==false ,elementProperties.id=isnull=''
But I always get only one element. Maybe it helps to define join hints????