After looking into this a bit more I have tracked the problem down to the following...
// look for existing category... existingCategory = findByName(category.getName()); if ((existingCategory != null) && (existingCategory.getId() != category.getId())) { throw new InvalidCategoryException("Category already exists"); } // we're good to update session.update(category); <--- this is where the error occurs.. I am getting the following exception: Another object was associated with this id (the object with the given id was already loaded) [eightotwo.fhe.model.content.hibernate.HibernateCategory#131074] Before I had session.saveOrUpdate() which was just creating a new Category object... is there a way to release the lock on the 'parentCategory' object so that I can update the object I want? Thanks! Justen Stepka ----- Original Message ----- From: "Justen Stepka" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, February 04, 2003 8:41 PM Subject: Re: [Hibernate] dependent object that is a reference to another hibernate object > Yup.. that's how I got the saves working before... here is my setup... > > <hibernate-mapping default-cascade="save-update"> > <class name="eightotwo.fhe.model.content.hibernate.HibernateCategory" > table="CATEGORY"> > <id name="id" column="categoryid" type="long"> > <generator class="hilo.long"/> > </id> > > <property name="active" column="active" type="boolean"/> > <property name="description" column="description" type="string"/> > <property name="name" column="name" type="string"/> > <property name="conception" column="conception" type="timestamp" /> > > <one-to-one name="parentCategory" > class="eightotwo.fhe.model.content.hibernate.HibernateCategory"/> > > <!-- need note mappings --> > <list role="notes"> > <key column="category_noteid"/> > <index column="listorder"/> > <one-to-many > class="eightotwo.fhe.model.audit.hibernate.HibernateNote"/> > </list> > > <!-- creator --> > <many-to-one name="creator" > class="eightotwo.fhe.model.security.hibernate.HibernateAdministrator" > column="admincreatorid"/> > </class> > </hibernate-mapping> > > then here is the HibernateNote object.. > > <hibernate-mapping default-cascade="none"> > <class name="eightotwo.fhe.model.audit.hibernate.HibernateNote" > table="NOTE"> > <id name="id" column="noteid" type="long"> > <generator class="hilo.long"/> > </id> > > <property name="comment" column="comment" type="string"/> > <property name="date" column="commentdate" type="timestamp"/> > > <!-- need to keep track of who set this note, must be admin --> > <many-to-one cascade="none" name="user" > class="eightotwo.fhe.model.security.hibernate.HibernateAdministrator" > column="administratorid"/> > </class> > </hibernate-mapping> > > I have been playing around for a bit.. but the problem that I am having now > is that when I call the following code: > > category = CategoryDAOFactory.getDAO().findById(id); > Note note = NoteDAOFactory.getDAO().newNote(); > User user = > UserManagerFactory.getManager().findAdministratorById(getUser().getId()); > note.setUser(user); > note.setComment(comment); > List notes = category.getNotes(); > notes.add(note); > category.setNotes(notes); > ContentManagerFactory.getManager().update(category); > > --- > > update more or less calls category.saveOrUpdate(); > > the the category object gets saved again.. and now I have to category > objects... each time I add a note and save the category this problem > happens... am I just missing the correct way to have the cacades setup? > > Thanks, > > Justen Stepka > > ----- Original Message ----- > From: <[EMAIL PROTECTED]> > To: "Justen Stepka" <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Tuesday, February 04, 2003 7:59 PM > Subject: Re: [Hibernate] dependent object that is a reference to another > hibernate object > > > > > > If you don't want the save() to cascade, you should set cascade="none" or > > cascade="delete" on the association to User. > > > > (Also, as long as unsaved-value is correct, the save() will cascade to an > > update() of the User, which is okay usually.) > > > > > > > > > > > > "Justen Stepka" > > <[EMAIL PROTECTED]> To: > <[EMAIL PROTECTED]> > > Sent by: cc: > > [EMAIL PROTECTED] Subject: > [Hibernate] dependent object that is a reference to another > > eforge.net hibernate > object > > > > > > 05/02/03 11:54 AM > > > > > > > > > > > > > > I am having a problem with my already existing objects being persisted > into > > the database when I call saveOrUpdate(). > > > > What happens is that I am putting the User object into my servlet session > > so > > that I can access the values of the account on the view (JSP pages). When > I > > call on an operation later in the system I may grab that User object out > of > > the session to set the value into a new object that is later persisted > with > > hibernate by calling saveOrUpdate(). > > > > This is where the problem occurs... when I save that new object with the > > User object as a reference it is being repersisted rather than looking at > > the identy field and seeing that the row/data in the datastore as the same > > object. > > > > Is there a way to force hibernate to look at the existing identify field > on > > the object I am setting rather than resave the existing object over again? > > > > Thanks. > > > > > > > > ------------------------------------------------------- > > 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 > ------------------------------------------------------- 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