-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: A Collection of records not saved properly.
PostPosted: Sun Oct 01, 2006 8:03 am 
Newbie

Joined: Sun Oct 01, 2006 6:33 am
Posts: 8
Hibernate version: 3
Name and version of the database you are using: MySQL 4.1

Hello. I have a strange problem, and while I'm burdened with all the hours staring at the code, the fresh look will hopefully easily find the "little pebble".

I have the following XDoclet annotation (and getter/setter definitions):

Code:

private Set answers = new HashSet();
...
/**
     * @hibernate.set table="ctx_answers" cascade="save-update" lazy="false"
     * @hibernate.collection-key column="ctx_id"
     * @hibernate.collection-many-to-many class="com.jimpanel.model.survey.QuestionAnswer" column="id"
     */
   public Set getAnswers() {
      return this.answers;
   }
   
   public void setAnswers(Set answers) {
      this.answers = answers;
   }

and
Code:
/**
* @hibernate.class table="q_answer"
*/
public class QuestionAnswer ....



When I save the session (Note: using org.springframework.orm.hibernate3.support.HibernateDaoSupport.getHibernateTemplate()) only the most recent answers are written to ctx_answers, and the rest is deleted.

However, all the answers are inserted in the q_answer table.

Right before calling the saveOrUpdate, I log the contents of the Set - it contains all the answers.

Why is that supposed to happen?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 01, 2006 5:28 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
My understanding is that when you use a Set you have to fetch all the data from the database when adding a new member to the set.

http://www.hibernate.org/hib_docs/v3/re ... entinverse

You may want to investigate using a Bag and you may look at setting invers=true in the parent. This may or may not work with other requirements that you have in the application.


Marius


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.