• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Auxiliary tables saving

Posts: 11
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic