How do I make a change to a production entity?

There are times when there is a need to make a change via code to a production entity and as such, bypassing the sandboxing bounds.

To do so we can leverage the EnterpriseStateManagerImpl.getEnterpriseStateManager().startProductionAdminFilterState(); functionality. When this is set, the changes will be made directly to production. Once this is complete, be sure to flip the switch back via the EnterpriseStateManagerImpl.getEnterpriseStateManager().endProductionAdminFilterState();. Here is a sample of how this would look like:

try {
// this ensures that we can make admin production level changes
EnterpriseStateManagerImpl.getEnterpriseStateManager().startProductionAdminFilterState();
// Custom code to make changes to a production entity...
} finally {
EnterpriseStateManagerImpl.getEnterpriseStateManager().endProductionAdminFilterState();
}

The usual will still apply such as needing to have a @Transactional annotation on the method and calling into a Service/Dao to save it.