Is it a good idea to use the date and time with the first or last few values of the session ID. Or should I just use the complete session ID value for my "unique id"?
Joined: Sep 01, 2004
Unique Id for what?
In general, I strongly discourage using any system's identifier for any purpose outside of it's stated purpose. The reason is that systems change and they're not expecting you to be using their session id for your system.
And so they change their behavior - which then may break your system.
Thus to be less risky - don't use the Java session identifier for your own unique identity. Instead generate your own unique ids. The simplest approach (assuming you're doing this for a database) - is to create a function that simply returns a counter (start with 1 and each request increments that number).
Make it static and synchronized to minimize chances of two users with the same id.
And then use a database or text file to remember the last count when your system shutsdown.
B Wiley Snyder
Joined: Nov 26, 2003
Originally posted by Mark Wilcox: Unique Id for what? Mark
For a shopping cart.
I need to send a unique id to the billing agent to identify and seperate different purchasers. I know I need to use the session variable for this and I've heard of different people using different versions, I've never heard of the your idea and I'm not really sure that its a good one for my cart. I have heard though of people using the date and time mixed with the session Id but I don't know if thats a good idea but would like to hear some feedback about it.
Thanks for the response
Joined: Aug 02, 2004
Logically a combination of customer number and order number would be unique, if not order number by itself. You could generate your order numbers as Mark suggests (good practice in my experience) or use an inverted timestamp such as 20040905233000, i.e. YYYYMMDDHHMISS format. If your system could realistically process more than one order in the same second you could add milliseconds or some other discriminator.
yeah you can surely go for sequences, as bear said.
but in Oracle 9i Certifcation Guide SQL/PLSQL published by McGraw Hill, dont remember the author. it is written there that it is not encouraged to use sequences to generate your primary keys when you really have to manipulate the records with that key.
sequences are best suited when you just want a unique auto-generated no. for your key column, and you are not gonna use that much while manipulating records.
cuz it has some parameters like,
lower limit upper limit
and sometimes later, when your database turns huge then you have to tune the sequences as well.
i think jules solution would be better. Enjoy the same no. of characters ever.