-->
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.  [ 7 posts ] 
Author Message
 Post subject: Do not use <list> and <map>
PostPosted: Thu May 10, 2007 12:05 am 
Newbie

Joined: Thu Apr 12, 2007 10:35 pm
Posts: 11
In doing some experimentation and research to resolve a problem, I came across the following comment from Sergey (late last year):

[url=http://forum.hibernate.org/viewtopic.php?t=967618&highlight=ilist+index+key]
Quote:
You can't use lists nor maps with <one-to-many> in NHibernate.

[/url]

First, can someone confirm that this is correct??

I love NHibernate and have been using it now for some time. I have spent many hours reading documentation, blogs, examples, etc. All of which refers to <list>, <bag> and <map> being the various collection types available.

I had read that <list> and <map> do not work with bi-directional associations but nowhere (until today!) had I read that <list> and <map> simply do not work at all with <one-to-many> collections.

If this is true, it seems misleading that this major shortcoming of NHibernate is not mentioned in the documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 3:37 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I don't know where you found my comment, but yes, I must have meant bi-directional (i.e. inverse="true") one-to-many associations.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 3:56 am 
Newbie

Joined: Thu Apr 12, 2007 10:35 pm
Posts: 11
Hi Sergey,

Thanks for clearing up.

(BTW found it in post # 967618).

However, a simple <list> or <map> (without inverse="true"), appears to generate an INSERT and an UPDATE for each item added to the list and therefore not really workable in production app.

Or am I missing something?

Thanks,
Phil


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 4:11 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
That happens because NHibernate maintains the association separately from the object itself. Hibernate already allows using inverse with indexed collections, so some future version of NHibernate will allow it too, but I don't want to speculate on when it will happen.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 6:45 am 
Newbie

Joined: Thu Apr 12, 2007 10:35 pm
Posts: 11
I am sure the bi-directional capability will be very welcome whenever that feature is made available.

However, does that mean there are no plans to correct the basic problem of a uni-directional <list> or <map> (i.e. without an inverse="true")? Surely the unnecessary calls seriously undermine the possibility of using NHibernate real-world enterprise-capable applications?

Is there any scenario where you would use a <list> or <map> in an app built using NHibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 1:16 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
After trying <list> and <map> and failing, we resorted to <bag> for every one-to-many collection in our application, which has almost 400 entities. All are marked inverse="true" and most have a sort-order attribute defined.

Having to use <bag> rather than <list> or <map> was one of the most frustrating and confusing parts of learning NHibernate ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 7:19 pm 
Newbie

Joined: Thu Apr 12, 2007 10:35 pm
Posts: 11
Glad to hear I'm not alone.

I guess the part which compounds the frustration is that the documentation for Hibernate and NHibernate both talk about <list> and <map> as if they are choices on par with <bag> and <set>.

However, from what I can surmise, it appears that:
- one-to-many collections only work properly (i.e. one sql call per row insert) if they are bi-directional, and
- <list> and <map> cannot be bi-directional.

There should be a big bold statement at the top of the NHibernate documentation connecting the dots on the above two statements and warning newcomers looking to use NHibernate in a production app : DO NOT USE <LIST> OR <MAP> FOR ONE-TO-MANY COLLECTIONS.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.