Hi.
I am trying to learn more of Hibernate by trying to make some forum.
I have a Forum class, a Thread class and a Message class.
I would like the Forum to have a collection of threads that are ordered by the latest message date.
Code:
<bag name="threads"
cascade="save-update"
inverse="true"
order-by="?">
<key column="THREAD_ID"/>
<one-to-many class="Thread"/>
</bag>
The problem is that I don't know what to put in the order-by, because the information has to come indirectly from messages and the association with threads.
I thought about making a formula to make a lastMessageDate in Thread. But this property does not have a column in the database, right? So how can I use it to order?
I also thought about making lastMessageDate a normal property and calculate the date in the Java code. But wouldn't that cause redundant information in the database?
What is the best way to map something like this?