when I'm making one object I need to look into database.object and find maximum key for that object in table. When I find maximum number, I need it to increase it by 1 and my new object will have that new key. These keys are dependent of object type, and there are many types, so I can't use id.
Example: Table objects
Id, Name, Type, Key
1, One, T1, 6
2, Two, T1, 3
3, Three, T2, 88
4, Four, T1, 101
Issue I'm facing: more users can make new object (and there is some calculations, so this operation is not very fast) and sometimes two or more users end's up with a same key?!
Using jdbc I could use SELECT .. FOR UPDATE and lock table.
Is there any recommended solution how I can achieve this using hibernate?
Thanks