Apache Cayenne > Index > Cayenne FAQ > Fetch By Primary Key
Added by Andrus Adamchik, last edited by Andrus Adamchik on Dec 21, 2007  (view change)

DataObjectUtils is your friend. It has a number of useful shortcuts to quickly and efficiently (i.e. using cache whenever possible) locate individual DataObjects.

Example:

DataContext context = // obtain DataContext using one of the standard methods
int pk = 5;
Artist artist = 
  (Artist) DataObjectUtils.objectForPK(context, Artist.class, pk);

More Info:

  1. DataObjectUtils in User Guide
  2. DataObjectUtils API