Skip to content
Advertisement

Filter rows in DataSet using JPA/Hibernate

I have the following code which is used to retrieve data from multiple tables (using joins) and then mapping every row into a DTOList but I also need to apply filters based on user preferences: per table1.name or table2.name, table3, etc.

So I just want to know what would be the best way to do it in terms of performance and best practices;

  1. retrieving all rows and then apply the filters with lambdas (easier)
  2. change the query to a dynamic query with Criteria or something else?
  3. Any other solution=?

Advertisement

Answer

I ended up creating the query on the fly; depending on the filters I get from UI i assemble the query with Java and send it to DB, it´s easier since this required many tables…

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement