Hi all,
I have a bidirectional @OneToMany relation in my model. I'm having trouble with the @IndexColumn annotation not beeing stored when cascading the parent of the relation.
Hibernate version:3.0.5
Annotations version: 3.0-beta2 edr2
Annotations:
Code:
@Entity
@Inheritance
@Table(name="multiple_choice_question")
public class MultipleChoiceQuestion extends Question {
....
@OneToMany(cascade=CascadeType.ALL, mappedBy="question")
@IndexColumn(name="index", base=0)
public List<Alternative> getAlternatives() {
return alternatives;
}
....
}
Code:
@Entity
@Table(name="alternative")
public class Alternative {
....
@ManyToOne()
@JoinColumn(name="question_id")
public MultipleChoiceQuestion getQuestion() {
return question;
}
.....
}
Unittest:Code:
public void testStoreMultipleChoiceQuestionAndAlternatives() throws Exception
MultipleChoiceQuestion mcq = new MultipleChoiceQuestion("Will it work?", null);
List<Alternative> alts = new LinkedList<Alternative>();
alts.add(new Alternative("alt1", "testdata", mcq));
alts.add(new Alternative("alt2", "testdata", mcq));
mcq.setAlternatives(alts);
dao.saveObject(mcq);
// -- commit session
commit();
MultipleChoiceQuestion m = (MultipleChoiceQuestion) dao.getObject(MultipleChoiceQuestion.class, mcq.getId());
assertEquals(2, m.getAlternatives().size());
dao.removeObject(MultipleChoiceQuestion.class, m.getId());
}
This results in all the properties of the alternative beeing stored correct except the index column that remains null. When reading back the question i get anorg.hibernate.HibernateException:
null index column for collection
I'm using postgres 7.4.7.
I've done the same thing with a unidirectional mapping and that works fine but I'm trying to follow the guidelines and make those mappings bidirectional.
Thanks in advance
/Robert Lerner