aspose file tools*
The moose likes Object Relational Mapping and the fly likes Auxiliary tables saving Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Auxiliary tables saving" Watch "Auxiliary tables saving" New topic
Author

Auxiliary tables saving

Tatiana Vorobeva
Greenhorn

Joined: Aug 06, 2011
Posts: 11

Hi all!

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).

Two questions:
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Auxiliary tables saving