Ok, I think I'm getting it. But to make things a bit more clear for myself, here are some mods to the original example:
Code:
<class name="Summary">
<subselect>
select item.name, max(bid.amount), count(*)
from item
join bid on bid.item_id = item.id
group by item.name
</subselect>
<synchronize table="item"/>
<synchronize table="bid"/>
<synchronize table="orders"/>
<id name="name"/>
<cache usage="read-write"/>
<property name="orderCount">
<formula>
select count(*) from orders o where o.name = name
</formula>
</property>
...
</class>
So since Summary does not map directly to orders, with the synchronize element, Hibernate will ensure that the orderCount property does not return stale data.
Now suppose the following scenario: The Summary class is immutable by the application and uses a cache strategy of "read-only". Also assume that we have a mechanism to notify the second level cache of external updates to cached date. The data for the orders table is modified by a non-hibernate source. Does the synchronize element buy you anything in this situation?
I assume that synchronize happens a Flush time, but what is happening under the hood and when? I've been looking through the sources to understand this more but I'm not finding what I'm looking for. Thanks!
Ryan-