Search code examples
hibernatejakarta-eehqlhibernate-mappingtransient

Java Hibernate - Is there a way to populate a Transient property with Formula


As the title says, is there a way to do it on a Transient property?

Asking this, because I know, as of sending data back to the FE, I set the transient property though, which is okay, but if I want to query it (ordering for example, ORDER BY) I am hitting a problem where the column is unknown (obviously).

Any way around it, to not remove the Transient annotation, or is it the only way?

Scenario: The property name is label, which gets constructed by salutation, title, firstname, lastname if it's a Customer object, if it's a Company object it's the companyName.

Thanks in advance!


Solution

  • seems to me like you are trying to come up with revolutionary solution instead of correct and fast one. Either

    1. Persist the value in DB and then use it in order by clause
    2. Order by several columns which you combine to create your transient property
    3. Keep the property transient and sort your results in application logic
    4. If you insist on ordering on DB level, create stored function in DB which would recreate your transient property from persisted values