fix cast exception raised under certain circumstances when determining target entity class for jpa relations