use an sql-query to load an entity

3 views
Skip to first unread message

mathmax

unread,
Aug 11, 2009, 9:39:03 PM8/11/09
to nhusers
It seems to be exactly what I need but it doesn't work by my side.
I would like to use a sql query to load an entity.


I followed the instructions in the documentation (http://nhforge.org/
doc/nh/en/index.html#querysql-load)

But I get this error:
Table 'magento131.Shipping' doesn't exist

Here is my mapping file:

<class name="Shipping" lazy="false">
<id name="Id">
<generator class="assigned" />
</id>
<property name="Label" update="false" />
<loader query-ref="shipping"/>
</class>

<sql-query name="shipping">
<return alias="ship" class="Shipping" />
select distinct shipping_method as {ship.Id}, REPLACE
(shipping_method , '_', ' ') as {ship.Label}
from delivery_days
</sql-query>

What am I doing wrong?

Thank you in advance for your help.

Fabio Maulo

unread,
Aug 12, 2009, 12:18:59 AM8/12/09
to nhu...@googlegroups.com
shipping_method as {ship.Id}
inverted

2009/8/11 mathmax <maximean...@gmail.com>



--
Fabio Maulo

Hamlet.Jiang

unread,
Aug 12, 2009, 1:36:38 AM8/12/09
to nhusers
This is very useful

On 8月12日, 下午12时18分, Fabio Maulo <fabioma...@gmail.com> wrote:
> shipping_method as {ship.Id}inverted
>
> 2009/8/11 mathmax <maximeandrighe...@gmail.com>

Bevan Arps

unread,
Aug 11, 2009, 10:21:23 PM8/11/09
to nhu...@googlegroups.com
This might be an overly simplistic question ...

On Wed, Aug 12, 2009 at 1:39 PM, mathmax <maximean...@gmail.com> wrote:

It seems to be exactly what I need but it doesn't work by my side.
I would like to use a sql query to load an entity.

But I get this error:
Table 'magento131.Shipping' doesn't exist

But does the table "magneto131.Shipping" exist?

Assuming behaviour similar to SQL Server 2008, if you want to specify the dbo namespace, you'll need to be explicit.

Cheers,
Bevan.

mathmax

unread,
Aug 12, 2009, 8:13:06 AM8/12/09
to nhusers
> shipping_method as {ship.Id}inverted
I don't understand. What do you mean by inverted ? It's like the
example: First the field to the database, then the corresponding
property of the entity

> But does the table "magneto131.Shipping" exist?
I create a query to avoid having to create a view or a table on the
database. So, no magneto131.Shipping doesn't exist.

Stefan Steinegger

unread,
Aug 20, 2009, 2:58:30 AM8/20/09
to nhusers
Where does this magneto131 come from? I is certainly not invented by
NH ...

mathmax

unread,
Aug 20, 2009, 3:30:41 PM8/20/09
to nhusers
magneto131 is the name of the mysql database (set in the config file).
But Nhibernate shouldn't look at a table called Shipping in this
database since the entity should be loaded via the sql query.

On 20 août, 08:58, Stefan Steinegger <stefan.steineg...@bluewin.ch>
wrote:

Stefan Steinegger

unread,
Aug 23, 2009, 5:12:31 PM8/23/09
to nhusers
So now I start to understand. You have an entity that does not map to
a table. Instead you write a custom sql to load it from any other
table.

I don't have much experience with custom sql queries and can't tell
you whats going wrong. But to identify the problem you should take a
look at the generated sql. Use some tool like profiler for Sql Server
or let NH write the generated sql to a log file. Then you will quickly
find out what NH is trying to do when this error happens.

I suspect that it tries to update the entity. (It's not immutable and
there is not sql for updating.)
Reply all
Reply to author
Forward
0 new messages