Fix for supporting hibernate proxies

Sometimes the objects that are obtained from the database are hibernate proxies, which are subclasses of the actual domain classes. This change is needed to properly handle these proxies.