• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate collection mapping problems - lists, bags and null list-index properties

 
Andy Westley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm pretty new to hibernate and it feels like I'm blagging my way through it. I thought I'd been stumbling in the right direction until I hit my latest problem. I'm trying to build a social networking app - you know users, friend invites, friendships, etc. I've always done my own DAOs and standard JDBC code in the past, but this felt complicated enough to warrant some ORM, but learning it as I'm going along is leaving me feeling a bit confused.

Basically I think my problems revolve around mapping collections. Building from scratch I would have assumed I would use ArrayLists as my properties, having followed a load of tutorials I've sort of ended up with Bags, I think it's causing a problem. I've included some code below - which I've simplified from my actual source just to save a bit of space.

User.hbm.xml

Invite.hbm.xml

As these stand, I can store a new invite, but I had assumed that the columns flagged as being list-index properties would be set automagically for me. Instead it's null, and when I try to return a list of invites for a user I get the following stack trace:

As I said, it's clear the list-index field is null which causes the error, but how do I make sure that's set? Is it automatic or do I need to do something?

I've switched away from the bags in the mapping config because I was beginning to run into errors where returning what I thought would be a Collection:


Is there enough in there to explain my problem? I think ultimately I want to be using List as my collection type but don't fully understand how and when the list-index field gets populated. I've got the caveat-emptor code and seen it too uses List in the item class, but I can't seem to trace how it gets used.

Any help would be gratefully received. I've come to far to think about rewriting this, but seem to have hit a brick wall. I can't seem to find any detailed examples of this working online, but there does seem to be quite a lot people struggling with it.

Cheers
aw


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic