-->
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: how to use TableHiLoGenerator to create id of type string
PostPosted: Sat Jan 19, 2008 9:48 am 
Newbie

Joined: Sat Jan 19, 2008 7:48 am
Posts: 1
Hi
I am trying to use the TableHiLoGenerator to generate a id *but* store it as as a string in the Table. Unfortunately, I am working on a legacy database where the row_id is a string. Ideally, I would like to use the TableHiLoGenerator and use type conversion (IUserType?) and add a prefix. For eg: if the id returned is (int)23, I would like to convert it to "1-00023" where "1" is the prefix and "-" is the seperator.

First things fist, I just wanted to see if the TableHiLoGenerator could store the id as a string and I ran into a road block

Here is the relevent mapping

<id name="Id" column="ROW_ID" type="string" unsaved-value="0">
<generator class="hilo">
<param name="table">hi_value</param>
<param name="column">next_value</param>
<param name="max_lo">100</param>
</generator>
</id>

The exception I got was

{"The type initializer for 'NHibernateRepository.Repository' threw an exception."}

and the inner Exception is

{"type is not a ValueTypeType\r\nParameter name: type"}

Looks like I cannot use the TableHiLoGenerator to generate an Int and put it as a string into the ROW_ID column thru automatic conversion.

Any idea how to implement a prefixed string id generator using TableHiLo algorithm?
Thanks
arkae


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 19, 2008 11:54 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
You gonna need to extend the NHibernate.Id.TableHiLoGenerator class.
Take a look, this it's the class, the exception thorws because it make a conversion thinking that you string, is a numeric representation.
https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/Id/TableHiLoGenerator.cs

Extend this type a make you own generator.

I'm porting Hibernate Shards, and I need to deal with a similar problem, I need to insert a Id, into a Guid, for example
If I generate this Guid:
3F2504E0-4F89-11D3-9A0C-0305E82C3301
I must convert it to
000D04E0-4F89-11D3-9A0C-0305E82C3301
This mean that the prefix is the number 13 (000D at hex)

This it's the implementation that I propouse:
https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate.Shards/src/NHibernate.Shards/Id/ShardedUUIDGenerator.cs

Best regards.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.