I recently stuck in a situation where I need to apply sorting but I have to apply sorting on those values which are calculated in my code and does not exist in the database. For this On the suggestion of Mr. M.K. Bharti and with the help of Mr. A. Pandey I got the way to sort on calculated values via Derived Properties, A derived property is one that takes its value from a SQL expression, often but not necessarily based on the value of one or more other persistent properties.


Here ‘totalCost’ is a derived property and we can use this property as a domain property but this will not persists in database.One thing which we have to keep in mind that the property referenced in formula must be persistence model not the object model. We can also refer the other domain properties in this formula.