Hi
I have a little problem, we're building some sort of content management system for NHibernate 1.2 GA. The thing is that we would like to be able to list the information structure without fetching the content of the individual content nodes. The Mapping looks something like this
Code:
<class name="Node" table="Nodes" discriminator-value="0" polymorphism="explicit" >
<discriminator column="ContentType" type="integer" />
<many-to-one name="Parent" column="ParentId" not-null="false" lazy="proxy"/>
<set name="Children" cascade="all" inverse="true" generic="true" >
<key column="ParentId" />
<one-to-many class="Node" />
</set>
[Properties and Key here]
<subclass name="Article" extends="Node">
[unimportant properties here]
<property name="Body" type="StringClob" >
<column name="Body" not-null="true" />
</property>
</subclass>
</class>
Everything works fine, but as a optimization we don't like that the Body property is fetched when runing a Native SQL Query looking like this:
Code:
<resultset name="NodeList">
<return alias="node" class="Node"/>
<return alias="readlog" class="ReadLog"/>
</resultset>
<sql-query name="Nodes.Roots" resultset-ref="NodeList">
<![CDATA[
select {node.*}, {readlog.*}
from Nodes {node}
inner join ( [inner query]) iq on iq.NodeId = node.NodeId
and (node.ParentId is null)
and (node.IsRemoved = (:removed))
and (node.IsDraft = :draft)
left join ReadLog as readlog on readlog.NodeId = node.NodeId
and readlog.UserId = :user
order by node.SortOrder desc
]]>
</sql-query>
The resulting query generated by the List() method still contains the 'Body'. The queries looks something like this:
Code:
NHibernate: select top 16 node.NodeId as NodeId53_0_, node.UserId as UserId53_0_, node.ParentId as ParentId53_0_, node.AttachmentId as Attachme5_53_0_, node.Subject as Subject53_0_, node.Hidden as Hidden53_0_, node.Locked as Locked53_0_, node.Removed as Removed53_0_, node.IsDraft as IsDraft53_0_, node.IsReviewed as IsReviewed53_0_, node.CreateDate as CreateDate53_0_, node.ModificationDate as Modific13_53_0_, node.Abstract as Abstract53_0_, node.AuthorIp as AuthorIp53_0_, node.PublishDate as Publish16_53_0_, node.AuthorIsAdmin as AuthorI17_53_0_, node.ThumbnailId as Thumbna18_53_0_, node.Body as Body53_0_, (select SUM(rl.TimesRead) from iFokus_ReadLog rn where rn.NodeId = node.NodeId) as formula3_0_, (select count(*) from Nodes m where m.ParentId = node.NodeId and m.IsHidden = 0 and m.IsRemoved = 0) as formula4_0_, node.ContentType as ContentType0_, readlog.ReadId as ReadId18_1_, readlog.NodeId as NodeId18_1_, readlog.UserId as UserId18_1_, readlog.ReadDate as ReadDate18_1_, readlog.TimesRead as TimesRead18_1_
from Nodes node
and node.GroupId in (select GroupId from GetGroupsForSite(@p0, @p1, @p2))
and node.ParentId is null
and (node.IsRemoved = (@p4))
and (node.IsDraft = @p5 )
left join ifokus_ReadLog as readlog on readlog.NodeId = node.NodeId
and readlog.UserId = @p6
order by node.ModificationDate desc; @p0 = 'fc290a50-3f12-4a50-83d5-d09c400b97a6', @p1 = 'Moderator, Administrator, Member', @p2 = '1', @p3 = 'False', @p4 = 'False', @p5 = 'False', @p6 = 'b09da1f7-30f3-420f-9085-8400ea48c73f'
The C# code looks like this:
Code:
IQuery query = null;
if (!user.Identity.IsAuthenticated)
{
query = context.CurrentSession.GetNamedQuery(namedQuery + "_anonymous");
}
else
{
query = context.CurrentSession.GetNamedQuery(namedQuery)
.SetEntity("user", user);
}
query.
.SetBoolean("removed", removed)
.SetBoolean("draft", draft);
query.SetFirstResult(start)
.SetMaxResults(results);
IList< NodeList > array = new List< NodeList >();
foreach(object[] row in query.List())
{
array.Add(new NodeList(row[0] as Node, row[1] as ReadLog));
}
return array;
How do I remove the StringClob Body property from the sql query?