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

Querying multiple child entities #152

Open
PabloLec opened this issue Apr 7, 2024 · 1 comment
Open

Querying multiple child entities #152

PabloLec opened this issue Apr 7, 2024 · 1 comment

Comments

@PabloLec
Copy link

PabloLec commented Apr 7, 2024

Hello,

I'm currently using rsql-jpa-specifications in a Spring Boot project and facing a challenge with querying entities based on conditions that span multiple child entities. I would appreciate any guidance or solutions you could offer, whether it's a native feature or requires custom code.

I have a parent entity MyEntity that has a one-to-many relationship with a child entity Property. Each Property entity has two fields: key and value.

@Entity
public class MyEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @OneToMany(mappedBy = "myEntity")
    private Set<Property> properties;
    // Getters and setters
}

@Entity
public class Property {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String key;
    private String value;

    @ManyToOne
    @JoinColumn(name = "my_entity_id")
    private MyEntity myEntity;
    // Getters and setters
}

I'm looking to query MyEntity based on conditions across multiple Property entities. Specifically, I want to find instances of MyEntity that have at least one Property with key equal to "Foo" and another Property with key equal to "Bar" AND value equal to "Baz".

Is there a way to construct such a query using rsql-jpa-specifications? If the library does not support this functionality directly, could you provide some advice on how I might implement this logic, possibly by extending the library or integrating custom specifications?

Thank you for your help!

@schotten
Copy link

Hy.
emphasizing. I have the same need and I can't make it work!

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

No branches or pull requests

2 participants