1

A is a table
a1 is a primery key in A
a2 is another field in A

I have created a java web based application and deployed in wildfly server. The field a1 is a readonly field to the enduser and it will show the maximum count of the rows in table A and a2 is an editable field. Now consider two end users are acessing this application at same time and trying to insert data into the table A. Both these users will see the same value for field a1 and give different values in the field a2. Now both the users submit the application and will insert data into A. This will result in inserting two rows with the same value for the field a1. But the field a1 is a primary key. So it should have distinct values.

How can I prevent this while inserting data in table A? Here do we need to apply threading concept?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Jithin Jose
  • 65
  • 1
  • 8
  • 2
    You could let the database autogenerate the primary key. – Joakim Danielson Sep 08 '19 at 10:10
  • Solve it the same way as you would without jsf. Let your jdbc or jpa layer help you. Effectively all ypyr tags aee not 'on-topic' (java is too generic, wildfly too specific (and unrelated) – Kukeltje Sep 08 '19 at 10:10

1 Answers1

1

Use ID generator. There are different types possible, e.g. based on database sequence like in Oracle, based on auto increment in MySQL.

Here are some good examples:

mentallurg
  • 4,967
  • 5
  • 28
  • 36