-->
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.  [ 7 posts ] 
Author Message
 Post subject: Generate unique alpha-numeric code ( like customer code)
PostPosted: Thu Sep 08, 2005 4:44 am 
Newbie

Joined: Thu Sep 08, 2005 4:38 am
Posts: 3
I have implemented the object using a unique key as usual.
Code:
<id name="Id" column="Id" type="Int32" unsaved-value="0">
    <generator class="native" />
</id>

But in addition to the auto-increment number, there should be a human
readable alpha-numeric number for objects like customer code or order
code.

e.g.:
CUS22456
ORD_A4567

Logic for implementing these codes can be encapsulated inside the
respective classes. In successful transaction the current number
should be saved with the object and it should update in the database
as the last number for the next object (customer or order).
What is the best way it implement this using NHibernate ? Is there any
special way to do his using the mapping file? Or is there any way to
trap the successful transaction of the current object. So this can be
easily handled with the code.

Koolb


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 6:26 am 
Newbie

Joined: Thu Aug 25, 2005 5:05 am
Posts: 6
It seems like a better idea to have the "user readable" number being calculated from the Id of the object. That way you wont have 2 series of numbers to keep track off in the database.

You wont have a record of the number in the database then though, if that is important, it should only matter if you want to change the method for calculating the human readable number..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 10:06 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
As Dan said, what you can do is adding "CUS" or "ORD" to the ID before displaying it... (you can prefix a number of 0 if you want)

eg:
ORD00107

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: Human readable reference no as a property
PostPosted: Fri Sep 09, 2005 7:55 am 
Newbie

Joined: Thu Sep 08, 2005 4:38 am
Posts: 3
Let


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 9:01 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can try programming your own ID generator, or using an interceptor to provide the ID value before saving the object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 10:15 am 
sergey wrote:
You can try programming your own ID generator, or using an interceptor to provide the ID value before saving the object.


I saw some samples about how to impliment a custom ID generator using hibernate/Java. But couldn't find any .NET samples. But can I impliment a custom number generator for a property ?

Do you mind explaining how to impliment a interceptor.


Top
  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 12:30 pm 
Newbie

Joined: Thu Sep 08, 2005 4:38 am
Posts: 3
Anonymous wrote:
sergey wrote:
You can try programming your own ID generator, or using an interceptor to provide the ID value before saving the object.


I saw some samples about how to impliment a custom ID generator using hibernate/Java. But couldn't find any .NET samples. But can I impliment a custom number generator for a property ?

Do you mind explaining how to impliment a interceptor.


I implemented the code by using a getter and returning concatenated string of Prefix + ID. But I would really like to know whether I can do it using custom ID generator for a property? I would also like to know what you meant my interceptor.


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