Where and when should I use the context.getPrimaryKey() method rather than just accessing the Primary Key field(s) directly?

Sathyanarayana Katakam

context.getPrimaryKey() is used when an instance is associated with an EJB object, and is used during the callback methods (ejbActivate, ejbPassivate, etc ..) and business methods.

This method should be called once the bean is associated with an EJBObject. As, if the bean is not associated with one, then you will get an IllegalStateException. The earliest you can call this method without getting an exception is in the ejbPostCreate() mtehod.