JDO支援一種持久化模型,這這種模型中持久性自動傳播到引用的對象。這種機制經常稱為“延伸持久(persistence by reachability)”或者“傳遞持久(transitive persistence)”。這意味著一旦一個已經持久化的對象引用了一個臨時對象,這個臨時對象自動變成持久化的。對於JDBC編程者,這個模型可能很奇怪,但是他們會發現這是大多數情況下編程者希望從持久化架構中得到的支援。
例子:pmf = (PersistenceManagerFactory) (Class.forName( "com.libelis.lido.PersistenceManagerFactory").newInstance());
pmf.setConnectionDriverName( "versant");
pmf.setConnectionURL(dbName);
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
tx.begin();
Provider aProvider =
new Provider( "LIBeLIS");
pm.makerPersistent(aProvider); // aProvider now persists
Address anAddress =
new Address( "25 rue Paul Barruel", "France", "Paris");
aProvider.address = anAddress ; // anAddress now persists
tx.commit();
pm.close();
例子pmf = (PersistenceManagerFactory) (Class.forName( "com.libelis.lido.PersistenceManagerFactory").newInstance());
pmf.setConnectionDriverName( "versant");
pmf.setConnectionURL(dbName);
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
tx.begin();
Provider aProvider =
new Provider( "LIBeLIS");
pm.makerPersistent(aProvider);
Address anAddress =
new Address( "25 rue Paul Barruel", "France", "Paris");
aProvider.address = anAddress ;
tx.commit(); // objects are stored into the data source, client cache is discarded, references are invalid
tx.begin();
System.out.println(aProvider); // aProvider is refreshed from the data source
tx.commit();
pm.close();
每次你修改了一個對象,它在JDO緩衝中對應的實體將被標示為“髒(dirty)”。
例子tx.begin();
aProvider.address = aNewAdr; // aProvider is marked as dirty
tx.commit(); // aProvider will updated in the data source