views:

1121

answers:

2

Hi, I'd like to map the following sql in NHibernate. Will I need to make a separate entity object i.e RoomTypeVO mapped to tb_tags to do this? Any help much appreciated.

SELECT dbo.tb_rooms.id, dbo.tb_rooms.name, dbo.tb_tags.name AS 'roomType' FROM dbo.tb_rooms INNER JOIN dbo.tb_tags ON (dbo.tb_rooms.typeID = dbo.tb_tags.id)

<id name="id" column="id">

  <generator class="native" />

</id>

<property name="name" />
+1  A: 

If you to a straight sql query you do not have to. If you want to use HQL you will have to work with an entity.

But, you can always do sql queries directly.

If you have a mapped entity then you could probably just do something like this:

FROM RoomType
Arthur Thomas
A: 

When you refer to 'FROM', are you thinking of something like this?

<property name="totalPrice"
formula="( SELECT SUM (li.quantity*p.price) FROM LineItem li, Product p
            WHERE li.productId = p.productId
            AND li.customerId = customerId
            AND li.orderNumber = orderNumber )"/>
I think he's referring to the syntax for a HQL query which makes the "select" clause optional. If you all want is a collection of entities, then "from EntityName" is sufficient.
cliff.meyers
yes, I was showing the query in HQL. I have lots of mappings and I haven't had to use formula yet, but to get a 'total' like you show above then a formula would be good.
Arthur Thomas