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

Add multiple joins in nested list #307

Closed
konopkin11 opened this issue Jul 2, 2023 · 1 comment
Closed

Add multiple joins in nested list #307

konopkin11 opened this issue Jul 2, 2023 · 1 comment
Labels
question Further information is requested

Comments

@konopkin11
Copy link

Suppose we have a Product class, that has an ProductAttribute field. The ProductAttribute class has a value field and object with id.

public class Product {

private List<ProductAttribute> attributes;

}

public class ProductAttribute {

private String value;
private Attr attr;

}
public class Attr{
private Long id
}
I want to be able to search for all products that has in attributes (value="RTX 2080" AND attr.id=1) AND (value="RGB" AND attr.id=3) on the same persisted Product object. How can I achieve that?

I have tried things, with no success, like:
http://localhost:8081/products/search?filter=((attributes.value:'RTX 2080' and attributes.attribute.id:'1') and (attributes.value:'RGB' and attributes.attribute.id:'3'))
but it makes only one join so hibernate makes somthing like
select p1_0.id,p1_0.category_id,p1_0.description,(SELECT SUM(p.stock) FROM productsize p JOIN products_product_sizes pps on p.id = pps.product_sizes_id WHERE pps.product_id =p1_0.id),p1_0.title from products p1_0 where exists(select 1 from products_attributes a1_0 join productattributes a1_1 on a1_1.id=a1_0.attributes_id join attribute a2_0 on a2_0.id=a1_1.attribute_id where a1_1.value='RTX 2080' and a1_1.attribute_id=1 and a1_1.value='RGB' and a1_1.attribute_id=3 and p1_0.id=a1_0.product_id) offset ? rows fetch first ? rows only

@torshid
Copy link
Member

torshid commented Aug 21, 2023

Can you try using the exists function? Like this:

http://localhost:8081/products/search?filter=exists(attributes.value:'RTX 2080' and attributes.attribute.id:'1') and exists(attributes.value:'RGB' and attributes.attribute.id:'3')

I think that it would work that way. Feel free to reopen if not.

@torshid torshid closed this as completed Aug 21, 2023
@torshid torshid added the question Further information is requested label Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants