• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Auxiliary tables saving

 
Greenhorn
Posts: 11
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic