-->
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.  [ 11 posts ] 
Author Message
 Post subject: Custom Id Generator bug?
PostPosted: Fri Sep 30, 2005 3:00 am 
Hi all,

I'm trying to build a custom Id generator - there don't seem to be any examples or and the hibernate dtd suggests implementing a default constructor and IIdentifierGenerator and IConfigurable if required.

I get an exception

System.ArgumentNullException: Value cannot be null.
Parameter name: type

It seems the IdentifierGeneratorFactory is not picking up the IType for the generator in:

NHibernate.Id.IdentifierGeneratorFactory.Create(String strategy, IType type, IDictionary parms, Dialect dialect)

Has anyone managed to create a custom Id generator?

Thanks
Oz


Top
  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 3:45 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Can you please provide full stack trace and mappings?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 1:32 pm 
I'm having the same problem. Here is the code:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="SurgeryHibernate.Domain.Facility, SurgeryHibernate" table="facility">
      <id name="Id" column="key_facili" type="String" unsaved-value="00000000">
         <generator class="SurgeryHibernate.Domain.PaddedSequenceGenerator" type="String">
            <param name="sequence">encs_facility</param>
         </generator>
      </id>
      <property name="name" column="facility" type="String" length="36"/>
   </class>
</hibernate-mapping>


Code:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using NHibernate.Id;
using NHibernate.Engine;
using NHibernate.Type;

namespace SurgeryHibernate.Domain
{
    class PaddedSequenceGenerator : SequenceGenerator
    {
        public override object Generate(ISessionImplementor session, object obj)
        {
            String result = base.Generate(session, obj).ToString();
            String NUMBER_PAD = "00000000";
            result = NUMBER_PAD.Substring(0, 8 - result.Length) + result;
            return result;
        }
    }
}


Top
  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 1:37 pm 
Newbie

Joined: Fri Sep 30, 2005 1:31 pm
Posts: 12
Whoops. Forgot to login.

Here's the stack:

{"The 'type' attribute is not declared."}

" at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream)\r\n at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering)\r\n at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)\r\n at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)\r\n at SurgeryDataGen.Program.Main(String[] args) in D:\\Projects\\Tempus\\DotNetProjects\\Surgery\\src\\SurgeryDataGen\\Program.cs:line 30\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 1:41 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
No, you're not having the same problem :) Your problem is that <generator> doesn't have type attribute.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 1:53 pm 
Newbie

Joined: Fri Sep 30, 2005 1:31 pm
Posts: 12
<generator class="SurgeryHibernate.Domain.PaddedSequenceGenerator" type="String">

It's there?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 2:38 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, you have it there, but it's not allowed.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 2:53 pm 
Newbie

Joined: Fri Sep 30, 2005 1:31 pm
Posts: 12
So where does it go? I used this same algo in Hib3 for Java and it didn't require a type other than in the id tag:

Code:
   <class name="com.tempus.hibernate.t1.domain.Facility" table="FACILITY">
       <id name="t1Id" column="key_facili" type="java.lang.String">
           <generator class="com.tempus.hibernate.t1.domain.id.PaddedSequenceGenerator">
                <param name="sequence">encs_facility</param>
           </generator>
       </id>
     <property name="name" column="facility" type="java.lang.String"/>


Last edited by tomdyess on Fri Sep 30, 2005 3:01 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 2:56 pm 
Newbie

Joined: Fri Sep 30, 2005 1:31 pm
Posts: 12
I added that type trying to figure out what it wanted - removed and similar error. The original location for the type is still intact:

<id name="Id" column="key_facili" type="String" unsaved-value="00000000">

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="SurgeryHibernate.Domain.Facility, SurgeryHibernate" table="facility">
      <id name="Id" column="key_facili" type="String" unsaved-value="00000000">
         <generator class="SurgeryHibernate.Domain.PaddedSequenceGenerator">
            <param name="sequence">encs_facility</param>
         </generator>
      </id>
      <property name="name" column="facility" type="String" length="36"/>
   </class>
</hibernate-mapping>


{"could not instantiate id generator for strategy 'SurgeryHibernate.Domain.PaddedSequenceGenerator'"}

{"Value cannot be null.\r\nParameter name: type"}

at NHibernate.Id.IdentifierGeneratorFactory.Create(String strategy, IType type, IDictionary parms, Dialect dialect)
at NHibernate.Mapping.SimpleValue.CreateIdentifierGenerator(Dialect dialect)
at NHibernate.Persister.AbstractEntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at SurgeryDataGen.Program.Main(String[] args) in D:\Projects\Tempus\DotNetProjects\Surgery\src\SurgeryDataGen\Program.cs:line 31
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 4:06 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Ok I fixed the code to throw a more informative exception. You are missing the assembly name in the class="...", so NHibernate can't load the type.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 4:18 pm 
Newbie

Joined: Fri Sep 30, 2005 1:31 pm
Posts: 12
Worked like a charm. Thanks a bunch.


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