Hi,
I was wondering how I could implement database locking using EJBs and JPA.
I am using glassfish and MySQL and I believe I have to set up some properties in the persistence.xml, but I don't know what these are.
It would also be useful if I could specify which entities beans need this locking strategy.
The reason for the question is that I wrote a simple ejbClient that accesses a session bean which in turn adds 1 to a column in the database table using an entity manager.
The client spawns 3 threads each try to update the same row but in there own transaction. When I run the client the different threads use the same entity and hence produce the folliwng output :
What I really need is to somehow synchronise the access to the entity beans, so that only 1 client can update it at once.
The code below is of the
test client
The session bean method does the following:
I would appreciate if someone could point me in the right direction.
Thanks