[#1251] Fix error on getting the newly created resources

We need to get the new resources to be able to create the default resource
views. To do so, we use the session's _object_cache. The problem is that the
current session might not have an _object_cache. This happens when the
transaction hasn't been flushed yet, or when it has been flushed but no new
objects were created.

This change supports both cases.