-->
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: Cannot create a custom id generator
PostPosted: Mon Jan 25, 2010 12:22 am 
Newbie

Joined: Mon Jan 25, 2010 12:06 am
Posts: 2
Hi all

I have an assembly called PersistentData containing the following class:
Code:
namespace PersistentData
{
    public class UUIDGenerator : IIdentifierGenerator
    {
        public const int TYPE_PREFIX_LENGTH = 8;
        public const string PERSISTENT_OBJECT_PREFIX = "persistn";

        private static IDictionary<Type, string> _typeToPrefix = new Dictionary<Type, string>();
        private static IDictionary<string, Type> _prefixToType = new Dictionary<string, Type>();

        static UUIDGenerator()
        {
            _typeToPrefix[typeof(IPersistentObject)] = PERSISTENT_OBJECT_PREFIX;
            _prefixToType[PERSISTENT_OBJECT_PREFIX] = typeof(IPersistentObject);
        }

        public static void registerType(Type type, string prefix)
        {
            _typeToPrefix[type] = prefix;
            _prefixToType[prefix] = type;
        }

        public static Type getTypeByUUID(string uuid)
        {
            return _prefixToType[uuid.Substring(0, TYPE_PREFIX_LENGTH)];
        }

        public object Generate(ISessionImplementor session, object obj)
        {
            var type = obj.GetType();

            while (!_typeToPrefix.ContainsKey(type) || type != typeof(object))
            {
                type = type.BaseType;
            }

            return _typeToPrefix[type] + "-" + Guid.NewGuid();
        }
    }
}


And I try to use it as a custom id generator like this:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="PersistentData" namespace="PersistentData">
  <class name="IPersistentObject" table="TBL_PERSISTENT_OBJECTS" abstract="true" >
    <id name="uuid">
      <column name="UUID"/>
      <generator class="PersistentData.UUIDGenerator"/>
    </id>
  </class>
</hibernate-mapping>


But when BuildSessionFactory() is called it throws an exception:
Quote:
Could not interpret id generator strategy: PersistentData.UUIDGenerator. Possible cause: no assembly name specified.


Does anyone know what's the problem?


Top
 Profile  
 
 Post subject: Re: Cannot create a custom id generator
PostPosted: Mon Jan 25, 2010 5:49 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You have to specify the assembly name:

<generator class="PersistentData.UUIDGenerator, PersistentData"/>

It seems that the default is not used here.

_________________
--Wolfgang


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.