I’m new to JPA and Hibernate and I have a problem with optimistic locking. I have a class which has an @Version annotated field. When I update the Entity represented by this class, the version counter does not increase. Here is my code: The class: and here is the main method: and here is what the consol…
Tag: transactions
Override transactional method
I have method M with @Transactional in service A. I have service B extends A with overrided method M. Will be overrided method M still transactional? Or I should add there @Transactional? Answer What you are actually asking : is the @Transactional annotation on the method inherited. Short answer : no. Annotat…
Where is the best place to begin transaction using Hibernate in a tired web application with Struts 2?
I got this Java web application which uses Struts 2 and Hibernate. In the most upper layer comprises of the Struts 2 action classes. Then there are my business logic classes which are responsible for the logic of the application. Finally there is a DAO layer (called Database Bridge) which is responsible for c…
Transaction marked as rollback only: How do I find the cause
I am having issues with committing a transaction within my @Transactional method: When I call methodB() from methodA(), the method passes successfuly and I can see “OK” in my logs. But then I get The context of methodB is completely missing in the exception – which is okay I suppose? Somethi…
Why do I need Transaction in Hibernate for read-only operations?
Why do I need Transaction in Hibernate for read-only operations? Does the following transaction put a lock in the DB? Example code to fetch from DB: Can I use session.close() instead of tx.commit()? Answer Transactions for reading might look indeed strange and often people don’t mark methods for transac…
How to start a transaction in JDBC?
Connection.setTransactionIsolation(int) warns: Note: If this method is called during a transaction, the result is implementation-defined. This bring up the question: how do you begin a transaction in JDBC? It’s clear how to end a transaction, but not how to begin it. If a Connection starts inside in a t…