Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding SelectList Value into DB

 
Kashif Mughal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic