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.  [ 4 posts ] 
Author Message
 Post subject: Using typed lists with bag/set/list mappings
PostPosted: Wed Jun 21, 2006 7:43 pm 
Newbie

Joined: Mon Jun 19, 2006 1:14 pm
Posts: 6
Hibernate version:
1.2.0

Mapping documents:
<bag name="Comments">
<key column="ArticleId"></key>
<one-to-many class="Data.ArticleComment, Data"></one-to-many>
</bag>

Name and version of the database you are using:
MSSQL 2005




I was wondering if there was any way to have bag/set/map/list return a generic list such as List<Article> or just a typed Array Article[] rather than an ArrayList, IList, Nhibernate Set, etc. I really hate having to cast everywhere when I know the exact type :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 9:06 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Check out either NHibernate Generics or NHibernate 1.2.0 Alpha1.

Edit:

And, if you go with the alpha version of nhibernate, then the code (straight from the test suite) would look like this:

<list name="Items" cascade="all-delete-orphan" generic="true">
<key column="a_id" />
<index column="a_idx" />
<one-to-many class="B" />
</list>

public IList<B> Items
{
get { return _items; }
set { _items = value; }
}


Last edited by benhyrman on Wed Jun 21, 2006 10:31 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 9:54 pm 
Newbie

Joined: Wed Jun 21, 2006 2:45 pm
Posts: 16
good post and answer - thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 1:35 am 
Newbie

Joined: Mon Jun 19, 2006 1:14 pm
Posts: 6
Thanks, I had to use bag instead of list with that example if I used list it would insert a null row on index 0 for some reason


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

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.