Hello,
Let’s say I have a table of a Workplace, which holds a List of Employee. I use the “one-step” approach to fetch them. Now, If I have a particular Workplace, and I want to retrieve a sorted list (by “firstname”, for example) of it’s Employees, What is the best way doing so?
Right, but for applying the addSortBy I need to query on the Employee class. it will return ALL the Employees in the table, not just the once related to a particular Workplace.
Well, I can, but this is a bit messy. if I have a huge inventory of Employees (10^6), it would be very ineffective going through all of them, just to sort a few Employees of a particular Workplace. After all, this is why I store a list of them in the Workplace table the first place, to keep it effective.
If you have a lot of data, try to use such workaround.
Firstly - add index for column “name” in your Employe table.
Secondary - do not create relations to Workplace (to avoid joins), just use column “WorkplaceId” and add index for this column too.
Then use dataQuery.setWhereClause() and addSortBy() as usuall.