Hi! I have difficulty understanding one to many mapping with lists. I use Oracle 10g and Hibernate 3. I have class Artist and class Song. Artist has a List of Song objects as field and Song has a Artist field. As far as I know I have to make a many-to-one association in Song.hbm.xml and a one-to-many association in Artist.hmb.xml. Now Song table has a foreign key to Artist table but Artist table doesn't have a foreing key to Song. I want to be able to load the Artist previously persited(I've also persisted Song objects) and iterate thru the Artist's list of Song objects. When i try this I get org.hibernate.HibernateException: null index column for collection which is obviously because I don't have a column Songs. My question is it is possible to do this (and if it is what have I done wrong in the mapping files) or do I have a problem understanding db design?If it isn't possible I think mapping collections isn't worth.
Here is the one-to many association of Artist.hmb.xml
And here is the many to one association of Song.hmb.xml:
list collection in mapping is used if the order of items is important and you have a column that stores the index number of the item.
It doesn't seem to be the case in your example. If you don't need the ordering, use a set collection and change your class to use a java.util.Set.
The subject of the topic was not good. It don't understand collection mapping, it doesn't matter the type. I want to be able when i load an Artist to get his Songs with his getSongs() method. But i get a org.hibernate.HibernateException: null index column for collection error.
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop