Added more code to entity persistence