saveOrUpdate() requires that (1) the object has an identifier property (2) the identifier class implements equals() and hashCode() (3) unsaved-value is set correctly
I recommend that you try enabling logging to see what Hibernate is doing. If you still can't find a solution, email me a simple main() method and I will figure out whats wrong very quickly, I'm sure. [EMAIL PROTECTED] "Raible, Matt" <[EMAIL PROTECTED]> To: "'[EMAIL PROTECTED]'" Sent by: <[EMAIL PROTECTED]> [EMAIL PROTECTED] cc: eforge.net Subject: RE: [Hibernate] Saving Children with composite-id 21/01/03 01:03 PM Is it possible that saveOrUpdate will not work for the children of this object, and I have to use update(obj, id) instead? Damn, I thought hibernate was easy and now it's kicking my ass! It's probably something super simple and I'm just not seeing it. To re-iterate (I know you guys hate me by now), here's a brief overview of my code. ** all classes extend from BaseObject with has equals(), hashCode() and toString() methods. Parent.java --- private Long id; private List children; +appropriate getters/setters Parent.hbm.xml --- <bag role="children" table="CHILDREN" cascade="all"> <key column="parent_id" length="22"/> <one-to-many class="eg.Child"/> </bag> Child.java --- private ChildId id; +appropriate getter/setter ChildId.java --- private Long parentId; private Long recordNum; + appropriate getter/setters Child.hbm.xml --- <composite-id name="id" class="eg.ChildId" unsaved-value="none"> <key-property column="parent_id" length="22" name="parentId" type="long"/> <key-property column="record_num" length="22" name="recordNum" type="long"/> </composite-id> I am able to retrieve children just fine, but when I try to save the parent, hibernate tries to do an insert and I get a unique constraint violation. I'm calling the following method to save everything: public Parent saveParent(Parent p) throws DAOException { storeObject(p); return (Parent) retrieveObject(eg.Parent.class, p.getId()); } I got the storeObject method from one of the examples floating around, so it could definitely be my problem: protected void storeObject(Object obj) throws DAOException { Session ses = null; try { ses = HibernateSession.currentSession(); 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 { HibernateSession.closeSession(); } catch (Exception ex) { ex.printStackTrace(); } ; } } Thanks, Matt ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel ********************************************************************** Any personal or sensitive information contained in this email and attachments must be handled in accordance with the Victorian Information Privacy Act 2000, the Health Records Act 2001 or the Privacy Act 1988 (Commonwealth), as applicable. This email, including all attachments, is confidential. If you are not the intended recipient, you must not disclose, distribute, copy or use the information contained in this email or attachments. Any confidentiality or privilege is not waived or lost because this email has been sent to you in error. If you have received it in error, please let us know by reply email, delete it from your system and destroy any copies. ********************************************************************** ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel