-->
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.  [ 1 post ] 
Author Message
 Post subject: storing an index into a bag
PostPosted: Tue Sep 15, 2009 4:30 am 
Newbie

Joined: Tue Dec 06, 2005 10:33 am
Posts: 4
Hi there,

sorry if this is a stupid question but i'm not sure of the best way to handle this. I have a class which contains a collection and I also want a property that points to one of these as a default so ideally i would like:

class A

public Item Default
{
}

public IList<Item> items
{
}

the bit I am struggling with is how to set this up in the hbm file and in the class as its really just points to one of the items in the bag but it stores the key of the item that is the default. When I create a new instance of class A and I want to set a default item I am having to use a transaction so I save the item first, get its new key and then add it to the class and then save that out too and I wrap this in a transaction but I was wondering if there is a tidier way of doing this?

here's what I do to save a new instance of class A and have a default item:

GetITransaction
{
Create new Item
Save it
Create Class A and add the new item to its collection (new item has an id now we have saved it)
Save Class A
commit
}

This works but is it the best way of doing this or am I missing something?

Thanks
Andrew.
}


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

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.