Hi. I have a huge doubt. What is an INSERT in Hibernate? Here is the case study:
I have a User object, which contain String username and String password, and let say List hobbies.
I populate these fields and perform persistence of object User:
Code:
User user = new User();
user.setUserName("boby");
List list = new ArrsyList();
list.add("tennis");
list.add("Golf");
user.setHobbies(list);
user.setPassword("someone");
getHibernateTemplate().saveOrUpdate(user);
Ok. I'm ok with that. But How to get the same effect as using INSERT statement when I use jdbc, in order to insert more hobbies(in this case) into user's list??? When I retrieve user from database, now I want to perform such an update (so the user object is retrived):
Code:
List updatedList = user.getHobbies();
updatedList.add("Some new Hoby");
, now, if I perform
Code:
getHibernateTemplate().saveOrUpdate(user);
the list has been replaced in database, with an old one?! and I do not want that.
If I use
Code:
getHibernateTemplate().save(user);
I get the two users with the same values of username and password?!
So, obviously, 'cause I'm new in Hibernate, I use wrong syntax for accomplishing insertion in database. Where do I wrong and what is the correct way, when I want to update the list of some data of user?
Thanks in advance!