PDA

View Full Version : NHibernate and custom loader


McQuak
12-27-2006, 10:45 PM
Hi all.
I'm using the <loader query-ref ... /> feature of NHibernate 1.2 for define custom SQL statement for entity loading.
But it seems that this doesn't work under Spring.Data.NHibernate12.
I have following hmb.xml (for test purposes)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Domain" namespace="Domain.Domain">
<class name="Product" table="Products">
<id name="ProductID" column="ProductID" type="System.Int32">
<generator class="hilo"/>
</id>
<property name="UnitPrice" column="UnitPrice" type="System.Decimal"/>
<property name="ProductName" column="ProductName" type="System.String" />
<loader query-ref="loadProducts"/>
</class>
<sql-query name="loadProducts">
<return alias="prod" class="Product" />
<![CDATA[
select
ProductID as {prod.ProductID},
UnitPrice as {prod.UnitPrice},
ProductName as {pod.ProductName}
from Products prod
order by ProductID desc
]]>
</sql-query>
</hibernate-mapping>


I have Dao class:

public class ProductDao : HibernateDaoSupport
{
public IList<Product> GetAll()
{
return this.HibernateTemplate.LoadAll<Product>();
}
}

But the returning IList of products is orderd by ProductID but not descending.
Even, when I make mistake in sql for loading, no error happend.

Is the custom loader usable under the Spring.Data.NHibernate12?

Thanks Tom.

Mark Pollack
01-06-2007, 08:15 PM
Hi,

I don't know off hand why this would be the case. I've made a JIRA (http://opensource.atlassian.com/projects/spring/browse/SPRNET-442) issue to remind me to investigate more. Thanks for your patience.

Mark

.ben
05-17-2007, 04:37 PM
This isn't because of the typo ?

ProductName as {pod.ProductName}

McQuak
06-02-2007, 08:08 AM
Unfortunately not.
Anyway, Spring does not use a query for loading... It's pity, since you try to tune the SQL loader.

McQuak
06-25-2007, 03:12 PM
My apologize.
I misunderstood the loader concept in the NHibernate. I thought the loader could be used for loading list of entities. But loader means entity loader not entities loader :o .

It works as expected.

Sorry

Tomas.