I have a USER(id, role_id, first, last) object, which contains a ROLE(id, role_name) object. ROLE are predefined in the DB, the data looks like: 0, user; 1, admin; 3 superadmin... What is the best way to persist (save) a USER and add role_id to the user based on the role_name? When creating the user, I know the role_name, but not the role id. Do I need to query the role id first then add it to the USER object? I am sure there is a smarter way to do it in Spring Data JPA. Please help, thanks.
Aucun commentaire:
Enregistrer un commentaire