IDENTITY function fix for Joined Inheritance

In a joined inheritance scenario, the identity function implementation assumed the foreign key column was on the table corresponding to the (sub)class named in the select statement. If the relation was on a super-class incorrect sql was generated.