i am experiencing problem in hibernate mapping as i want to develop a relationship between Item and User.
As the business logic is User is already registered in the system and he/she wants to upload his/her item, one by one, if he has more than one item.
So there are three classes,
all the attributes not worth mention.
MY PROBLEM IS I WANT INSERT INTO ITEM TABLE AND CREATE LINK IN USER_ITEM TABLE CORRESPONDING TO THE USER WHO UPLOADED ITEM (AS ONE USER MAY HAVE MANY ITEMS) BUT HERE ONE USER IS HAVING ONLY ONE ITEM.
BUT HIBERNATE IS RUNNING THIS QUERY BEFORE INSERTING IN USER_ITEM DELETING ALL THE ITEMS CORRESPONDING TO THAT USER.
Hibernate: insert into ITEM (.......................)
Hibernate: update USER set(.............)
Hibernate: delete from ITEM_USER where USERID=? <<--------------------------------------
Hibernate: insert into ITEM_USER (USERID, ITEMID) values (?, ?)
User.java Set<Item> items = new HashSet<Item>(); other attributes and getter / setters.
Please do not write in all caps. It is usually associated with yelling and reduces readability a lot.
For your question.
Is there a special reason that you made the entity item_user?
If I understand correctly you are trying to define a join table. This can be done more easily by hibernate itself via the mapping.
The wikibooks link oneToMany might help you.