-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: What does <synchronize> actually do?
PostPosted: Wed May 24, 2006 3:38 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
This is more of a curiosity question than anything, but I'm curios as to what the <synchronize> element actually does and when is it approriate to use? Section 5.1.3 of the documentation:

http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-class

shows this element being used, but it doesn't go into the specifics of what it does and why you would want to use it. What I'm most curious about is if this element is useful for cached enties which use formulas to derrive a property. Thanks.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 7:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
It informs hibernate what is being accessed so it can co-ordinate the subsystems etc correctly.
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"/>
    <id name="name"/>
    ...
</class>

Shows item and bid are beign accessed but since it is native SQL hibernate has no idea what is tables/entities are being touched. Synchronize informs hibernate so it can deal with possible flush initiation, caching etc depending on the context of how summary is being used.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 11:52 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
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-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 6:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If it is truely readonly and assuming no updates to the tables involved (via hibernate mapping etc) then I see no need. It does not hurt and code changes but thats a different issue :-).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.