problema de concurrencia (datos obsoletos) en JPA
Digamos que tengo métodos con la siguiente firma
Object getData(int id) {
//create a entity manager
//get data frm db
//return data
}
updateData() {
Object obj = getData(id)
//get entity manager
//start transcation tx
//update
//commit tx
}
¿Ahora causará un problema de concurrencia? ¿Pueden los datos estar obsoletos en el peor de los casos? P.ej. si yogetData
y para cuando actualice, si alguien actualiza los datos, miupdateData
tendrá datos obsoletos? Ahora puedo usar lo siguiente: ¿Resolveré el problema?
Object getData(int id,Entitymanager em) {
//get data frm db using em
//return data
}
updateData() {
Object obj = getData(id)
//get entity manager em
//start transcation tx
//getdata using getData(id,em)
//commit tx
}