I have the project: Spring + Hibernate + want to use JSF
I have one main class, f.e. User (userId + userDetails + some other fields) and one additional class, f.e. UserDetails (userDetailsId + user + userId + other fileds).
The reason - dividing often used data (User) and rarely used data (UserDetails).
In User class userDetails mapped this way:
To make it work I should made two parameters in UserDetails class:
First - to make link between two classes in Java.
Second - to avoid an error (because there should be a field with the same name as in @PrimaryKeyJoinColumn annotation).
This way makes a problem: if I create UserDetails (and they are linked to User) before User is saved in DB - UserDetails will be saved in DB with user_id = 0 (because Hibernate saves them before the main record - User - and this User is not exist in DB at this moment).
This is a problem for me, because I want to save them in DB together (it's not good to delete a record in the Table each time then operator decides to cancel further user creation).
1. Should I connect Java classes (create User parameter in UserDetails to store the link to the User) or keep it divided with only userId (long) parameter? Did it because of a habit to have some link to the parent record in DB (user_id in user_details table).
2. At present, to store all data correctly I'm saving User with a null in UserDetails parameter, then - create UserDetails - saveOrUpdate User again. Will user_id be stored correctly, if I save User (with already created and linked UserDetails, which will be stored in DB with 0 in user_id) and right after that saveOrUpdate UserDetails (not the whole User)?
I want to make beans User + UserDetils to use them in JSF, and I'm trying to organize it correctly, but a little bit confused.