Jeff,

Why not have the primary key be login name, and have another field
which is the lowercased name. Then you can create a unique database
index on each field.

Jeff Schnitzer wrote:
>
> Hi everyone, I am dumbfounded by what I imagine should be a common and
> many-times-solved problem.  I would love to know how people are
> addressing this situation:
>
> I have a more-or-less typical membership-based website.  Users can sign
> up and create accounts; users can choose their unique login name.
>
> I've modeled the user as a CMP entity bean called Member.  Now, what to
> choose as the primary key?
>
> The natural option (and the one I chose) was to use the login name as
> the primary key.  But I want to make this key case-insensitive (there
> cannot be both "Bob" and "bob"), and there doesn't seem to be a natural
> way of doing this.
>
> I have a feeling it will work if a) my PK class does case-insensitive
> comparisons and b) I instruct the my container to use more interesting
> sql for findByPrimaryKey().  But I'm not sure that (b) is something I
> will be able to do for all containers.  Actually, I'm not even sure that
> this is something I'll be able to do for my own container.  Is this the
> "correct" solution to the problem, and I should stop worrying about it?
>
> Another approach which has some significant appeal is to use a generated
> integer primary key independent from the name.  Now the problem is, how
> do I guarantee that two users do not create accounts nearly
> simultaneously with the same login name?  It seems to me that simply
> ensuring that findByName() returns nothing and then saving the value
> opens up the opportunity for a race condition.  How can I protect
> against this?
>
> Ok, I could add another entity/table, "AllocatedName" which simply
> stores the downcased version.  Or I could use a singleton RMI server to
> provide a locking service.  But isn't this a little excessive?  There
> has got to be an easier way... and given the number of sites out there
> that work like mine, this must have been done dozens of times already.
> What am I missing?
>
> Thanks,
> Jeff Schnitzer
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

--
________________________________________________________________________________

Evan Ireland              Sybase EAServer Engineering        [EMAIL PROTECTED]
                            Wellington, New Zealand               +64 4 934-5856

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to