I'm guessing you are appending the entire where condition because the
actual condition , i.e. what you are filtering on is dynamic.  I'm
honestly not sure if there's a way to make what you're trying to do
work, but if you aren't tied to using straight SQL and have an
NHibernate-mapped Person entity in your system you can work with, I
think a more natural NHibernate approach to solving that problem would
be to use a Criteria Query-the Criteria API really shines for
constructing a dynamic query on the fly:

http://www.nhforge.org/doc/nh/en/index.html#manipulatingdata-criteria

Alternatively, if you're just trying to dynamically filter on some
differing set of properties on Person, example queries are great-you
just new up a person, set the properties you want to match on, say
LastName, and pass that in.

http://www.nhforge.org/doc/nh/en/index.html#querycriteria-examples

If you're doing this to get an entity with only certain properties (as
in some kind of DTO), there are other alternatives-you could query
using the methods described above, then use something like
AliasToBean, or look at Projections to transform your results into the
shape you need....

Good luck!


On Wed, May 13, 2009 at 8:33 PM, abragg <[email protected]> wrote:
>
>
>
> IN converting over a legacy application we need to convert named query
> to nhibernate. The problem is that the where clause is being set.
>
> here is the mapping
>
> <resultset name="PersonSet">
> <return alias="person" class="Person">
>  <return-property column="id" name="Id" />
>  <return-property column="ssn" name="Ssn" />
>  <return-property column="last_name" name="LastName" />
>  <return-property column="first_name" name="FirstName"/>
>  <return-property column="middle_name" name="MiddleName" />
> </return>
> </returnset>
>
> <sql-query name="PersonQuery" resultset-ref="PersonSet" read-
> only="true" >
>  <![CDATA[
>  SELECT
>  person.ID as {person.Id},
>  person.SSN as {person.Ssn},
>  person.LAST_NAME as {person.LastName},
>  person.MIDDLE_NAME as {person.MiddleName},
>  person.FIRST_NAME as {person.FirstName},
>  FROM PERSONS as person
>  where :value
>  ]]>
> </sql-query>
>
> and the c# code: String query = "person.LAST_NAME = 'Johnson'";
> HibernateTemplate.FindByNamedQueryAndNamedParam("PersonQuery",
> "value", querry);
>
> the error: where ?]; ErrorCode []; An expression of non-boolean type
> specified in a context where a condition is expected, near '@p0'.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to