Currently, Liferay saves portlet preferences in the database. However, this means that it is impossible to override these portlet/page preferences even with custom code.
The only way to change page/portlet preferences once they are set is to call deletePortletPreferences() to delete the entry from the database, then use another method to write the preferred preferences.
Some however, using deletePortletPreferences() to delete directly from the database can result in an "org.hibernate.StaleStateException". This might be caused by a race condition between the cache refreshing and Liferay trying to read the portlet preferences, though this is just a guess since debugging does not trigger the StaleStateException.
An improvement would be to create a way to clear or override the saved preference through the code, something like:
This way, one would not need to make database calls and potentially cause a race condition.