6.1. Finding an Object by Identity

In Chapter 1, we introduced the concept of persistence by reachability and how an entire object graph of dependent objects is persisted when an object is saved. The simplest way to find an object is through its identifier. In Chapters 3 and 5, we covered the concepts surrounding object identity and how the getObjectID() can be used. You may recall that the JDOHelper class exposes a getObjectID(Object pc) method that returns the JDO identity associated with the parameter.

The PersistenceManager interface exposes a corresponding getObjectById() method that can be used in the application code to retrieve the instance through its JDO identity.

This example code taken from the example ObjectIdentityExample.java in ...

Get Core Java™ Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.