This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Adding SelectList Value into DB

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

With all my little knowledge with hibernate, I am trying to work on a relationship between CATEGORY and ITEMS. Its a simple one to many relationship but when i try to add an ITEM it also adds the category again for that item. That should not be the case; Category is just a select list in the Gui.

My poor mappings are as follow;






I know this is something very tiny but cant find, So Please F1 F1 F1
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quick question. Are you setting both sides of the relationship. Meaning are you adding the Item to the collection in Category, and are you setting the Item's Category, and htat Category that you are adding being the one that has the id set. If you are adding a Category that doesn't have an id, then it will do an insert on that Category object.

Also, do you have interfaces for your domain objects? Usually you don't.

Mark
 
Kashif Mughal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Are you setting both sides of the relationship. Meaning are you adding the Item to the collection in Category, and are you setting the Item's Category, and htat Category that you are adding being the one that has the id set. If you are adding a Category that doesn't have an id, then it will do an insert on that Category object.



Yes I do have the bi-directional relationship, I mean Category has Set of Items and Item has Category object. When I am adding item, I expect to take the Category id from the Gui(selectList) that is populated from Categories in DB. I dont want it to add new category.

So, I might have done some wrong relationship or concept. Classes are as follow;



About Interfaces for the Domain Objects I had them before but not now, just did not changed the names. By the way Which classes should have and not have interfaces ?
reply
    Bookmark Topic Watch Topic
  • New Topic