-->
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.  [ 1 post ] 
Author Message
 Post subject: troubles trying to implement user type, able to store GUID
PostPosted: Wed Oct 24, 2007 4:04 am 
Newbie

Joined: Fri Oct 19, 2007 3:47 am
Posts: 3
Location: Moscow
How can I implement the User Type, able to handle guids from Oracle and MS SQL (raw16 and uniqueidentifier both). Target is to get xml-mapping and persistent classes, applicable to DBses.

my implementation (fails cause of "wrong column count") :

Code:
public class MyGuid : IUserType
   {
      #region .акр.т.е атр..ут.
      private static readonly SqlType[] _sqlTypes = { SqlTypeFactory.Guid, SqlTypeFactory. GetBinary(16) };
      private System.Guid? _value;
      #endregion
...
      public object NullSafeGet(
         IDataReader resultSet,
         string[] names,
         object owner)
      {
         int index = resultSet.GetOrdinal(names[0]);
         if (resultSet.IsDBNull(index))
         {
            return null;
         }
         try
         {
            _value = (System.Guid?)resultSet.GetValue(index);
         }
         catch
         {
            _value = new System.Guid?(new Guid((byte[])resultSet.GetValue(index)));
         }
         return _value;
      }
      public void NullSafeSet(IDbCommand statement,
               object value,
               int index)
      {
         if (value == null)
         {
            ((IDbDataParameter)statement.Parameters[index]).Value = DBNull.Value;
         }
         else
         {
            System.Guid? guid = (System.Guid?)value;
            ((IDbDataParameter)statement.Parameters[index]).Value = value;
         }
      }
...


xml-mapping, f.example:
Code:
   <class name="BusinessLayer.Classes.PERSON, BusinessLayer" table="PERSON">
      <id name="Id" type="BusinessLayer.MyGuid, BusinessLayer">
         <column name="OBJECTID"  not-null="true" unique="true" index="PK_PERSON"/>
         <generator class="BusinessLayer.GuidRawGenerator,BusinessLayer" />
         <!--<generator class="native" />-->
      </id>



Help, pls.


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

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.