• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

one-to-many list mapping

 
Greenhorn
Posts: 25
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
Ionut Barau
Greenhorn
Posts: 25
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic