Use @GenerateValue to automatically generate Id of Entities instead of UUID.randomUUID() #12708
Labels
committers only
Difficult; better left for committers or more senior developers
enhancement
New feature or request
p.Low
Very little impact; unlikely to do in the near future
Milestone
Environment:
v9-migration
Description of feature/enhancement
Use @GeneratedValue for entities instead of using UUID.randomUUID() for sql entities.
For example,
![image](https://private-user-images.githubusercontent.com/55353265/300158251-81b23b93-c6ab-4bfd-9a4f-6d9ac40b1dd7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1NDE1ODYsIm5iZiI6MTcyMTU0MTI4NiwicGF0aCI6Ii81NTM1MzI2NS8zMDAxNTgyNTEtODFiMjNiOTMtYzZhYi00YmZkLTlhNGYtNmQ5YWM0MGIxZGQ3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIxVDA1NTQ0NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJlODE4MjlmMDZmZGJkMTA2ZTFmODdmMjQ2M2QzNWUxMmZkOGZjZjRjNmFlYzEzMTdlNjIzOWU1MWE3NmY4M2YmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.3HwWceBUbcLHNkVSzjmoUO5eOS9m-b4eYIuIkj8kex0)
we should add a @GeneratedValue for the @id field.
Justification
While there is a low chance of collision using UUID.randomUUID(), there is still a small chance of failure if the random UUID generated in
![image](https://private-user-images.githubusercontent.com/55353265/300158318-4512bf74-604a-448b-aec8-7c5967e5c8b9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1NDE1ODYsIm5iZiI6MTcyMTU0MTI4NiwicGF0aCI6Ii81NTM1MzI2NS8zMDAxNTgzMTgtNDUxMmJmNzQtNjA0YS00NDhiLWFlYzgtN2M1OTY3ZTVjOGI5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIxVDA1NTQ0NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFkNGVjNWUxNDFjZDlkZDJhMDVjNzE2ZWZmZDI5MmM3MjQ5NzhjYTM0ZDViMjY3ZGE1Nzk0Mzc3MTA4OGQ2NjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.HZFRzjuQopzNCH4J6CV2aopoO4R9ni2FQh4SJmGHW6I)
teammates/src/main/java/teammates/sqllogic/core/DataBundleLogic.java
persistDataBundle
method.Instead, a better practice might be to use @GeneratedValue annotation to generate a safe UUID for the respective entities such as
Section
,Student
etc.This would prevent a collision bug from ever occurring.
The text was updated successfully, but these errors were encountered: