Hi, i have the next many to one relation:
_____________WORKS_______________
WORK_ID (PK) BIGINT AUTOINCREMENT
WORK_CODE VARCHAR(10)
USER_ID BIGINT (FK)
___________USERS_________________
USER_ID (PK) BIGINT AUTOINCREMENT
I have to generate the UNIQUE column WORK_CODE with the following format:
4 digits alphanumeric code identifying the owner (user)-6 digits autonumeric. For example, i'll have this 2 work_codes for one user.
A001-000100
A001-000101
The next work for another user wil be:
A002-000100
A002-000101
.
.
So, i have to query for the last work of the user and then calculate the code. I must to isolate this process of concurrent access. What is the better aproach to do this? (Triggers, synchronized method...)
Thank you.
|