Fixed nullpointers on null foreignKey