Fix generated Persisted classes causing ClassCastException on hot-reload

Avoid causing casting errors due to stale Persisted classes being cached: detect a classloader change and clear the cache appropriately.