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.  [ 6 posts ] 
Author Message
 Post subject: Where is NHibernate.SqlTypes.TimeSqlType()?
PostPosted: Mon Dec 04, 2006 9:59 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
Hi.

I'm using the last version of NH (1.2.0 beta 2) and I've tried to compile an old implementation of IUserType and I'm getting the following error:

Quote:
Error 2 'Bremen.DTO.Types.MyTimeSpan' does not implement interface member 'NHibernate.IUserType.GetHashCode(object)' D:\Projetos\WingraphEx\VersaoDotNet\DTO\DTO\Types\MyTimeSpan.cs 11 18 DTO


So, to correct this, I've done the following:

Code:
        public int GetHashCode(object o)
        {
            return 0;
        }


I think it's not right, but it's just a test. After this, I've tried to compile again and got this error:

Quote:
Error 2 The type or namespace name 'TimeSqlType' does not exist in the namespace 'NHibernate.SqlTypes' (are you missing an assembly reference?) D:\Projetos\WingraphEx\VersaoDotNet\DTO\DTO\Types\MyTimeSpan.cs 23 66 DTO


So, my question is: where is the NHibernate.SqlTypes.TimeSqlType?

I need this type to map a TIME column from mySQL.

My full IUserType implementation is here:

Code:
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.Type;

namespace Bremen.DTO.Types
{
    public class MyTimeSpan : IUserType
    {
        /// <summary>
        /// Public default constructor
        /// </summary>
        public MyTimeSpan() { }       
       
        /// <summary>
        /// The SQL types for the columns mapped by this type.
        /// </summary>
        public SqlType[] SqlTypes
        {
            get { return new SqlType[] { new NHibernate.SqlTypes.TimeSqlType() }; }
        }

        /// <summary>
        /// The type returned by <c>NullSafeGet()</c>
        /// </summary>
        public System.Type ReturnedType
        {
            get { return typeof(System.TimeSpan); }
        }

        /// <summary>
        /// Compare two instances of the class mapped by this type for persistent "equality"
        /// ie. equality of persistent state
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool Equals(object x, object y)
        {
            return TimeSpan.Equals(x, y);
        }

        /// <summary>
        /// Retrieve an instance of the mapped class from a JDBC resultset.
        /// Implementors should handle possibility of null values.
        /// </summary>
        /// <param name="rs">a IDataReader</param>
        /// <param name="names">column names</param>
        /// <param name="owner">the containing entity</param>
        /// <returns></returns>
        /// <exception cref="HibernateException">HibernateException</exception>
        //      /// <exception cref="SQLException">SQLException</exception>
        public object NullSafeGet(IDataReader rs, string[] names, object owner)
        {
            int i = rs.GetOrdinal(names[0]);

            if (rs.IsDBNull(i))
                return null;
            else
            {
                string t = rs[i].ToString();
                return TimeSpan.Parse(t);
            }
        }

        /// <summary>
        /// Write an instance of the mapped class to a prepared statement.
        /// Implementors should handle possibility of null values.
        /// A multi-column type should be written to parameters starting from index.
        /// </summary>
        /// <param name="cmd">a IDbCommand</param>
        /// <param name="value">the object to write</param>
        /// <param name="index">command parameter index</param>
        /// <exception cref="HibernateException">HibernateException</exception>
        //      /// <exception cref="SQLException">SQLException</exception>
        public void NullSafeSet(IDbCommand cmd, object value, int index)
        {
            if (value == null)
                ((IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
            else
            {
                IDataParameter parm = (IDataParameter)cmd.Parameters[index];
                TimeSpan ts = (TimeSpan)value;
                parm.Value = new TimeSpan(ts.Hours, ts.Minutes, ts.Seconds);
            }
        }

        /// <summary>
        /// Return a deep copy of the persistent state, stopping at entities and at collections.
        /// </summary>
        /// <param name="value">generally a collection element or entity field</param>
        /// <returns>a copy</returns>
        public object DeepCopy(object value)
        {
            return value;
        }

        /// <summary>
        /// Are objects of this type mutable?
        /// </summary>
        public bool IsMutable
        {
            get { return true; }
        }

        public int GetHashCode(object o)
        {
            return 0;
        }
    }
}


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 8:48 pm 
Newbie

Joined: Sun Jul 31, 2005 7:53 pm
Posts: 17
Aaaah, the joys of using undocumented beta code, eh?

I don't know if it'll fix your problem, but if you look at TimeSqlType.cs from the NHibernate 1.1 source, it's just a wrapper for...

Code:
new SqlType( DbType.Time )


...so maybe they decided to remove some of the clutter. So your code would become...

Code:
public SqlType[] SqlTypes
{
            get { return new SqlType[] { new SqlType( DbType.Time ) }; }
}


I think the same thing has happened to Int32SqlType.

Also, I think GetHashCode should probably just be...

Code:
public int GetHashCode(object o)
{
            return o.GetHashCode();
}


...but that's just a guess.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 3:25 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, many types were removed to reduce the number of files. SqlTypeFactory class contains fields for the removed types.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 7:29 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
Ok rkennard and sergey.

Thanks a lot!

But I've changed the NH dll to the version ALPHA to continue using... Now I would like to change again to NH 1.2.0 Beta 2 to test what you said. So, I've done it!

Now I'm getting the following error:

Quote:
Could not find schema information for the element 'urn:nhibernate-mapping-2.0:hibernate-mapping'.


Ok, as I've read, the version of the "schema" has changed to 2.2... but is it necessary to update all my hbm.xml files?

Man, there are more or less 100 hbm.xml files in my DTO project :S

Don't you know another way?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 27, 2007 7:51 pm 
Newbie

Joined: Mon Jan 01, 2007 6:18 pm
Posts: 11
Location: New Zealand
hbm.xml files is not the only way of creating mappings.

You can do incode mappings which are available in the nhibernate.contrib part of the nhibernate manual


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 28, 2007 6:40 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Visual Studio 2005 has "Search and Replace in Files".


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