aspose file tools*
The moose likes Object Relational Mapping and the fly likes Adding SelectList Value into DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Adding SelectList Value into DB" Watch "Adding SelectList Value into DB" New topic
Author

Adding SelectList Value into DB

Kashif Mughal
Ranch Hand

Joined: Jun 19, 2008
Posts: 44
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


Thanks in Advance,
Kash.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kashif Mughal
Ranch Hand

Joined: Jun 19, 2008
Posts: 44
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 ?
 
 
subject: Adding SelectList Value into DB
 
Similar Threads
Item - Bid Unidirectional PROBLEM !!!
Hibernate
How to specify relationship in mapping file
hibernate migration
Foreign Key Constraint Fails