Ummm theres a bunch of things to get right and since I can't see your mappings, I'm not sure which. However, you should check out the functionality of:
* unsaved-value attribute of <id> * cascade attribute of associations * lazy attribute of collections * proxy attribute of <class>, <subclass>, <joined-subclass> by fiddling with those I think all your problems will go away ;) -----Original Message----- From: Matt Raible [mailto:[EMAIL PROTECTED] Sent: Friday, 27 December 2002 7:34 PM To: [EMAIL PROTECTED] Subject: [Hibernate] saveOrUpdate vs. update I have a BaseDAO that contains some generic (I think) Hibernate compatible code. It's basically removeObject, storeObject, and retrieveObject. I've found that Hibernate tries to do an INSERT if I use sess.saveOrUpdate in the following method: protected void storeObject(Object obj) throws DAOException { Session ses = null; try { ses = sessionFactory.openSession(); ses.saveOrUpdate(obj); ses.flush(); ses.connection().commit(); } catch (Exception e) { try { ses.connection().rollback(); } catch (Exception ex) { e.printStackTrace(); } ; throw new DAOException(e); } finally { try { ses.close(); } catch (Exception ex) { ex.printStackTrace(); } ; } } This causes an error, as there is already a user with this name. So I tried changing it to just ses.update(obj), but now I'm getting the following error: [junit] Testcase: testAddResume(org.appfuse.persistence.UserDAOTest): Caused an ERROR [junit] cirrus.hibernate.HibernateException: The given object has a null identifier property [org.appfuse.persistenc e.Resume] [junit] org.appfuse.persistence.DAOException: cirrus.hibernate.HibernateException: The given object has a null ident ifier property [org.appfuse.persistence.Resume] [junit] at org.appfuse.persistence.BaseDAOHibernate.storeObject(BaseDAOHibernate.ja va:117) [junit] at org.appfuse.persistence.UserDAOHibernate.addResume(UserDAOHibernate.java :117) [junit] at org.appfuse.persistence.UserDAOTest.testAddResume(UserDAOTest.java:91) All I'm trying to do is the following: user = dao.getUser("tomcat"); user.setAddress("new address"); User savedUser = dao.saveUser(user); assertEquals(savedUser.getAddress(), user.getAddress()); But it seems to be trying to go and persist the children - can I turn this off? Also, I've noticed that my user's children are retrieved when I get the user's information. Does this mean that if I create a bunch of mappings from user to other entities, that they're all going to be loaded when I get a user's information? This might not be desirable since I get a user's information when they login, and if they have a whole bunch of records associated with their name... you get the idea... Thanks, Matt ********** CAUTION - Disclaimer ********** This message may contain privileged and confidential information. If you are not the intended recipient of this message (or responsible for delivery of the message to such person) you are hereby notified that any use, dissemination, distribution or reproduction of this message is prohibited. If you have received this message in error, you should destroy it and kindly notify the sender by reply e-mail. Please advise immediately if you or your employer do not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of Expert Information Services Pty Ltd ("The Company") shall be understood as neither given nor endorsed by it. The Company advises that this e-mail and any attached files should be scanned to detect viruses. The Company accepts no liability for loss or damage (whether caused by negligence or not) resulting from the use of any attached files. **EIS******** End of Disclaimer ********** ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel