If you use that solution, please have a look to WARNING. 2011/3/25 Krzysztof Koźmic <[email protected]>
> So I have a one-to-many tables in database that looks like the following > (I'm on NHibernate 3.1): > > blog > id > title > author > > comments > id > blog_Id > languageid > comment > > and I want to map it to a *single* class with *single* comment property > that maps to text column in comments table for current language. > > Basically the idea is identical to one ayende had few years back: > http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx > > The difference is I try to accomplish this without subselect but using > <join /> instead (mostly because the table with translations has more > columns than just the text that I may need to include in my joined class). > > So I created a solution for that and I'm also using filter to pass language > id to queries. I also have a noop property in my mapping for the languageid > as well as where clause in my mapping that does the filtering. > > And here's the SQL that NHibernate generates: > > SELECT this_.Id as Id0_0_, > this_.Author as Author0_0_, > this_.Title as Title0_0_, > this_1_.Comment as Comment1_0_, > this_1_.LanguageId as LanguageId1_0_ > FROM Blog this_ > inner join Comment this_1_ > on this_.Id = this_1_.Blog_id > WHERE (this_.LanguageId = 2 /* @p0 */) > > The SQL is invalid as the where should be on this_1_.LanguageId as the > value comes from the joined table, not the main one. > > Also the LanguageId column is mapped as access="noop" which TTBOMK should > mean it won't be queried for so I'm surprised to see NHibernate is trying to > select it as well. To me it is just wasting bandwith. > > So I have two questions now. > > 1. How can I accomplish what I'm trying to get to. > 2. Are those issues I mentioned (invalid where clause and ignoring noop > access) bugs in NHibernate or am I looking at it from the wrong angle? > > Reproduction demo app (along with database dump) available here if someone > wants to play with it: http://ge.tt/5xoiqYY > > cheers, > Krzysztof > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
