This content has been marked as final. Show 1 reply
egesr wrote:Because when you start the transaction after you find the entity, the entity is not managed within that transaction. Container Managed Transactions, study it well.
I've a servlet that is using JTA, but it doesn't work as I expected when I begin the transaction before finding the entity.
The transaction is injected with the annotation:
private UserTransaction utx;
And in the servlet code I have written the next code:
Book requestedBook = em.find(Book.class, bookId);
int inventory = requestedBook.getInventory();
int newInventory = inventory - 1;
I don't know what is happening but the changes are not persised to the database.
If I begin the transaction before finding the entity, it works, but I don't understand why it doesn't work when I start the transaction after finding the entity.
Thank in advance