Could someone please clarify something for me?
This code doesn't error, but it doesn't save the 'call' object which is a child of 'checklist'. I would have hoped that when I call 'checklist.getSecurityCalls().put(...)' Hibernate would be smart enough to save (thereby generating the new call PK under the hood) or updating the existing object.
Code:
ChecklistValue checklist = (ChecklistValue) getHibernateTemplate().get(ChecklistValue.class, new Integer(checklistId));
Iterator keys = securityCalls.keySet().iterator();
while(keys.hasNext()) {
Integer key = (Integer)keys.next();
SecurityCallValue call = (SecurityCallValue)securityCalls.get(key);
updateLastModifiedOn(call);
checklist.getSecurityCalls().put(key, call);
}
getHibernateTemplate().update(checklist);
This code does save the child object. But, only because I'm saving it explicitly.
Code:
ChecklistValue checklist = (ChecklistValue) sess.get(ChecklistValue.class, new Integer(checklistId));
Iterator keys = securityCalls.keySet().iterator();
while(keys.hasNext()) {
Integer key = (Integer)keys.next();
SecurityCallValue call = (SecurityCallValue)securityCalls.get(key);
updateLastModifiedOn(call);
Integer id = (Integer)sess.save(call);
call.setSecurityCallId(id.intValue());
checklist.getSecurityCalls().put(key, call);
}
I'm having a little trouble understanding how Hibernate is being useful to me in regards to the one-to-many relationship I have. It's not saved me any lines of code. I can understand that the relationship saves me some time when
reading the checklist back in (complete with my map of 'call' objects though.
Am I missing something in the first listing that would make it work in the way I expect?
Thanks