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: Non-string criterion values coerced to string if ignore case
PostPosted: Thu Dec 21, 2006 6:01 pm 
Newbie

Joined: Thu Dec 21, 2006 5:48 pm
Posts: 4
I created a custom type for an Enum that I need persisted with 4-letter codes to the database, and in the overrides for the type for the set method, I am converting from the enum value to a string. While executing a find using criteria, this is failing with an InvalidCastException as NHibernate is passing the value of the enum in as a string. Here is the code from my type:

Code:
        public override void Set(System.Data.IDbCommand cmd, object value, int index)
        {
            string enumString = ToString(value);

            ((System.Data.IDataParameter)cmd.Parameters[0]).Value = enumString;
        }

        public override string ToString(object val)
        {
            switch ((BusinessEntities.TicketStatus)val)
            {
                case BusinessEntities.TicketStatus.Open:
                    return "OPEN";
                case BusinessEntities.TicketStatus.Closed:
                    return "CLSD";
                case BusinessEntities.TicketStatus.Canceled:
                    return "CNCL";
                default:
                    throw new ArgumentOutOfRangeException("value");
            }
        }


I think I tracked it down to a conversion that NHibernate does of any value to a string if ignore case is specified (I'm using an EqExpression). The relevant code (from SimpleExpression.cs) is below. Is this by design, or should it be considered a bug?

Code:
      public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
      {
         object icvalue = [b]_ignoreCase ? _value.ToString().ToLower() [/b]: _value;
         return new TypedValue[]
            {
               criteriaQuery.GetTypedValue( criteria, _propertyName, icvalue )
            };
      }


Thanks,
-jason


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 26, 2006 7:12 pm 
Newbie

Joined: Thu Dec 21, 2006 5:48 pm
Posts: 4
Should I file this as a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 10:22 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Feel free to report this if you can provide a simple test case with the report.


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.