Programming : Items related to programming and programming languages.
Updated: 2/2/2004; 2:44:38 PM.

 

Subscribe to "Programming" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Friday, January 09, 2004

When you retrieve an object with Toplink, no matter if it's through the ClientSession or a UnitOfWork, Toplink returns an object that it is tracking in its cache. If you change the object in one place, ask for it again in the other, you will get the changed object. In some cases this is great because you can quickly and easily reflect the latest information with incredible performance. However I find myself being confused by this behavior for most of my applications.

My idea is that each of the classes you store with Toplink implements Cloneable. Then, in your DAO layer (you are using a DAO layer, right?) , before you return an object to the caller you call its clone() method. This will ensure that you have a shallow copy of the object that is not associated with Toplink's cache. Then, you can count on 2 retrievals of the same object only reflecting any updates that have actually been committed to the cache/database.

If you have a complex object graph that you are persisting with Toplink and you want the same functionality, you can implement a method to do a deep clone. This would make sure that the entire graph reflects the data at that point in time rather than any changes that are happening in other places.


3:47:30 PM    comment []

© Copyright 2004 Tom Pierce.



Click here to visit the Radio UserLand website.

 


January 2004
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Oct   Feb

Search

 
How this works

Emacs Sources
 tsql-indent.el
 user-add-sql-folding-marks
 remove-line-boundary-in-region
 convert-camel-to-underscore

My Subscriptions
 Funny
 KM