-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL Expressions, YesNo type and SetBoolean
PostPosted: Thu Nov 15, 2007 8:05 pm 
Newbie

Joined: Thu Nov 15, 2007 7:54 pm
Posts: 1
Hi,

I am using nhibernate 1.2.0 with Firebird 1.5. My map file like this:

Code:
<property column="SCHOOLForm" type="YesNo" name="SchoolForm" not-null="true" length="1"/>


In my HQL, my query looks like this:

Code:
where en.SchoolForm = :schoolForm


Then I am using SetBoolean("schoolForm", false) to set the value to False. I am assume nhibernate would set the value to "N", but when I look at nhibernate log, it looks like this:

Code:
11:36:32.931 [5] DEBUG NHibernate.Loader.Loader - BindNamedParameters() False -> schoolForm [1]
11:36:32.931 [5] DEBUG NHibernate.Type.BooleanType - binding 'False' to parameter: 1


It seems bind 'False' to the query. Is something wrong with my setups?

In nhibernate-development list, Fabio Maulo suggest me to change like this:

The solution is type="Boolean".
Take a look to the hibernate.cfg.xml at:

Code:
<property name="query.substitutions">true 1, false 0, yes 1, no 0</property>

If you want map the property to a VARCHAR(1) use:
Code:
<property name="query.substitutions">true Y, false N, yes Y, no N</property>


But after I change to Boolean type, it become worse, nhibernate raise follow error

Code:
---> NHibernate.ADOException: could not execute query
---> System.FormatException: String was not recognized as a valid Boolean.
   at System.Boolean.Parse(String value)
   at System.String.System.IConvertible.ToBoolean(IFormatProvider provider)
   at System.Convert.ToBoolean(Object value)
   at NHibernate.Type.BooleanType.Get(IDataReader rs, Int32 index)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
   at NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
   at NHibernate.Loader.Loader.Hydrate(IDataReader rs, Object id, Object obj, ILoadable persister, ISessionImplementor session, String[][] suffixedPropertyColumns)
   at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, Type instanceClass, EntityKey key, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session)
   at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)



Does anyone give me a hint please?

Cheers,

Tao


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 1:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
If the .NET type of your SchoolForm property is a bool, the minimal mapping would be the following and NHibernate is usually smart enough to figure out the rest and do the right thing.
Code:
<property column="SCHOOLForm" name="SchoolForm"/>

Particularly, there is usually no need to explicitly specify the type.

_________________
Karl Chu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.