973637 wrote:It sounds something where you can use sequence instead of updating a table. Much safer IMHO.
Thank you all for responding on this issue. Based on the conversation, i am modifying my code and will explain exact need.
Some points to be noted-
1. I don' anything to be returned by function. I am good to with void.
2. The "value" will be set based on the "name" we are passing.
3. Since this table is common to all thread or program, so make what a particular thread selects, it updates on same value.
And here is the reason behind need for this-
We are using JPA as ORM. This uses a table (a common table) where it puts all the entities to be persisted with their last value used.
In my example MyTable is that table used by JPA.
as i describe itTest1, Test2... are name of entities. So if i say Test1 has "value" 10, means if a thread comes to insert a row in Test1, the uidpk of Test1 will be used
1, Test1, 10 2, Test2, 20 3, Test3, 30 4, Test4, 40
by that thread must 11. That thread is responsible to use next available uidpk from Mytable and update the same. So Thread used value as 11 for Test1,
It will update the same on MyTable as well. If we executewill return 11. And so on. Depending on application thread can insert more than one row at a time.
select value from mytable where name='Test1'
If you are still with me, a big thank you for this.
So point is, if application uses JPA and why i should write such code. To answer this some application are using Non-JPA technology. Application which are using Non-JPA technology can also insert row in Test1, Test2... and there i need to select last value used for uidpk and update the value used and make sure no other thread get dirty value.
Hope i am clear now.