Refactoring generate PrimaryKey