-->
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.  [ 8 posts ] 
Author Message
 Post subject: could not interpret type: AnsiStringFixedLength
PostPosted: Wed Aug 31, 2005 9:33 pm 
Newbie

Joined: Wed Aug 31, 2005 9:29 pm
Posts: 14
I need SchemaExport to create a column of type CHAR(12). It looks like AnsiStringFixedLength is what I need, but I get the following error:

Additional information: could not interpret type: AnsiStringFixedLength

Shouldn't this map directly to NHibernate.SqlTypes.AnsiStringFixedLengthSqlType?

I have searched nhibernate.org, hibernate.org and this forum for "AnsiStringFixedLength" with no luck.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 7:00 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I don't have any experience on that; did you try to set the length attribute in your mapping ?

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 5:11 am 
Newbie

Joined: Wed Aug 31, 2005 9:29 pm
Posts: 14
Yes, but that produces VARCHAR(12), not CHAR(12).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 8:22 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
It looks like using VARCHAR is a design choice... And I don't know how to change that.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 1:26 pm 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
I suggest that you raise it as a bug on Jira

_________________
Paul Hatcher
NHibernate Team


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 5:51 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
What does your mapping look like? I would guess that
Code:
type="Char" length="12"
should work, but I'm not able to check it right now.


Top
 Profile  
 
 Post subject: System.InvalidCastException : Specified cast is not valid.
PostPosted: Thu Nov 17, 2005 10:54 am 
Newbie

Joined: Wed Dec 22, 2004 12:04 pm
Posts: 7
I have the same problem

i try the solution to specified the lengh of the Char

Code:
<property name="CountryCode" type="Char" column="pays_id" length="3" />



But i receive a n exception when i try to insert

Code:
at NHibernate.Type.CharType.Set(IDbCommand cmd, Object value, Int32 index)
   at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index)
   at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object value, Int32 index, ISessionImplementor session)
   at NHibernate.Persister.EntityPersister.Dehydrate(Object id, Object[] fields, Boolean[] includeProperty, IDbCommand st, ISessionImplementor session)
   at NHibernate.Persister.EntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, SqlString sql, Object obj, ISessionImplementor session)


Top
 Profile  
 
 Post subject: solution to multiple char(x)
PostPosted: Fri Nov 18, 2005 11:48 am 
Newbie

Joined: Wed Dec 22, 2004 12:04 pm
Posts: 7
I have implement a IUserType to provide solution for mapping for char with length more than one

If you find an improvement or Bug in this code. Please send me and email

Code:
/// <summary>
   /// Summary description for MultipleCharType.
   /// </summary>
   public class MultipleCharType:NHibernate.IUserType
   {
      private static readonly bool IsDebugEnabled;
      private static NullableType multipleChar = NHibernate.NHibernateUtil.String;

      static MultipleCharType()
      {
         //cache this, because it was a significant performance cost
         IsDebugEnabled = LogManager.GetLogger( typeof( IType ).Namespace ).IsDebugEnabled;
      }

      private ILog Log
      {
         get { return LogManager.GetLogger( GetType() ); }
      }

      public MultipleCharType()
      {
      }

      #region IUserType Members

      public new bool Equals(object x, object y)
      {
         if(x==y) return true;

         string lhs = (x==null) ? null : (string)x;
         string rhs = (y==null) ? null : (string)y;

         return multipleChar.Equals(lhs, rhs);
      }

      public NHibernate.SqlTypes.SqlType[] SqlTypes
      {
         get
         {
            return new SqlType[] { multipleChar.SqlType };
         }
      }

      public object DeepCopy(object value)
      {
         return value;
      }

      public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index)
      {
         if(value.Equals(null))
         {
            if( IsDebugEnabled )
            {
               Log.Debug( "binding null to parameter: " + index.ToString() );
            }
            ( (IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
         }
         else
         {
            if( IsDebugEnabled )
            {
               Log.Debug( "binding '" + value.ToString() + "' to parameter: " + index );
            }
            //Change the DBtype because the find query will not work
            IDataParameter parm = cmd.Parameters[ index ] as IDataParameter;
            parm.DbType=System.Data.DbType.AnsiStringFixedLength;
            parm.Value = value;
         }
      }

      public Type ReturnedType
      {
         get { return typeof(System.String); }
      }

      public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner)
      {
         int index = rs.GetOrdinal( names[0] );

         if( rs.IsDBNull( index ) )
         {

            if( IsDebugEnabled )
            {
               Log.Debug( "returning null as column: " + names[0]  );
            }
            return null;
         }
         else
         {
            string  charValue  =(string)multipleChar.NullSafeGet(rs, names);
            if( IsDebugEnabled )
            {
               Log.Debug( "returning '" +  charValue  + "' as column: " + names[0] );
            }
            return charValue.TrimEnd(' ');
         }
      }

      public bool IsMutable
      {
            get { return multipleChar.IsMutable; }
      }

      #endregion
   }


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