-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Example from NHibernate Reference Documentation doesn't work
PostPosted: Mon Aug 06, 2007 10:45 am 
Newbie

Joined: Fri Aug 03, 2007 9:35 am
Posts: 8
Hi, I tried the criteria example from "NHibernate Reference Documentation" but I wasn't succesfull.

There's an exception: {"Failed to convert parameter value from a String to a Double."}

Do you have any ideas, what could be wrong???

Thanks!


CODE:

DetachedCriteria avgWeight = DetachedCriteria.For(typeof(Cat))
.SetProjection( Projections.Avg("Weight") );

session.CreateCriteria(typeof(Cat))
.Add( Subqueries.Gt("Weight", avgWeight) )
.List();


CLASS:
using System;
namespace MvNHibernateTest
{
public class Cat
{
private string id;
private string name;
private char sex;
private double weight;
public Cat()
{
}
public virtual string Id
{
get { return id; }
set { id = value; }
}
public virtual string Name
{
get { return name; }
set { name = value; }
}
public virtual char Sex
{
get { return sex; }
set { sex = value; }
}
public virtual double Weight
{
get { return weight; }
set { weight = value; }
}
}
}

MAPPING FILE:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="MvNHibernateTest" assembly="MvNHibernateTest">
<class name="Cat" table="Cat">
<id name="Id">
<column name="CatId" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex" />
</id>

<property name="Name">
<column name="Name" length="16" not-null="true" />
</property>
<property name="Sex" />
<property name="Weight" />
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 11:00 am 
Newbie

Joined: Fri Aug 03, 2007 9:35 am
Posts: 8
I add the complete exception:

The query and the subquery seem to be good...

Select * from Cat where ? in (subquery) .

The only problem is with "?"
If you replace it with "Weight", everythink is OK. But nhibernate doesn't do this.

HERE'S THE EXCEPTION

{"could not execute query\r\n[ SELECT this_.CatId as CatId0_0_, this_.Name as Name0_0_, this_.Sex as Sex0_0_, this_.Weight as Weight0_0_ FROM Cat this_ WHERE ? > (SELECT avg(this_0_.Weight) as y0_ FROM Cat this_0_) ]\r\nPositional parameters: 0 Weight\r\n[SQL: SELECT this_.CatId as CatId0_0_, this_.Name as Name0_0_, this_.Sex as Sex0_0_, this_.Weight as Weight0_0_ FROM Cat this_ WHERE ? > (SELECT avg(this_0_.Weight) as y0_ FROM Cat this_0_)]"}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 11:25 am 
Newbie

Joined: Fri Aug 03, 2007 9:35 am
Posts: 8
SOLVED!!!

The problem is, that you must use Subqueries.PropertyGt insted of Subqueries.Gt

Watch out! There's an error in documentation!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.