I used a table that has a autonumber thru a control table. Lets call this column the pk. I have another column userLoginName which I keep unique. Since I am not allowed to change the pk I will have the benifit of being able to change the loginName under some rare circumstances.
When I create a entity bean and the loginName already exiusts it throws a CreateException. And there is no sure way of knowing what is the cause ( unlike wityh a duplicateKeyException ) because loginname here is not a Primary key just a unique field.
The only way to handle this seems to be that I do a findXXX method first to check the unique key existence.
What do u guys thiunk? Got any sugegstions?
Is that a bad design to have a automumber pk and a unique loginName?
You should not rely on the receipt on a FinderException to tell you that an entity does not exist in the DB. For a CMT bean, the container might throw this exception before the DB is accessed.
You could instead not use a finder, try and create the entity in the DB and handle CreateException. The problem is that the client cannot be sure what happened as the container may throw this exception after the transaction was committed. So, on balance, I guess the least worst approach is to use the finder method.