I have requirement of auto increment value in 2 tables with referential relation. My requirement is to insert data in two tables :- Table A = Rowid , other columns Table B = Rowid , other columns I need to insert data from different methods in both tables. Currently, I have taken this approach :- a. Query the max from Table A and add 1 to it. b. Insert data in both tables with value obtained in step 1 using batch update. However, flaw with approach is if two users/threads call this method at same time , they may end up having same value and I will get referential intergity error on Table A and Table B will have 2 rows with same row id .
I can syncronize my method to avoid that , however I have multiple different methods doing same due to some other functionality.
Ideal way to do this is to use autogenerated column, but out DBA is not allowing same. Also, this referential integrity between two table needs to be maintained by application , actual constraint is not allowed by DBA.
I am using Spring jdbctemplate on java side and DB2 on database side. However, problem is independent of poth.