Record is getting saved and commited before completion of transaction

16 views
Skip to first unread message

Govinda Sakhare

unread,
Jun 5, 2021, 1:21:25 PM6/5/21
to jDBI

Hi Folks,

I have below piece of code, in the snippet, I am updating employee table followed by that updating department table. In the below code employee table is getting updated and committed even before completion of this transactional method. Can somebody please help me understand why it's happening? I am using Oracle DB with default TransactionHandler.

@Transaction 
public void updateEmployee(Employee employee, Department dept) 
    employeeDao.updateEmp(employee);          
    TimeUnit.SECONDS.sleep(90); // Pause 
    employeeDao.updateDepartment(dept) 


Thanks,
Govinda

Steven Schlansker

unread,
Jun 7, 2021, 1:22:10 PM6/7/21
to jd...@googlegroups.com
Hi Govinda,
Jdbi is not responsible for enforcing transaction isolation, that is something the database engine does.
Is it possible your transaction isolation is configured either at the database, driver, or connection pool level to be in READ UNCOMMITTED isolation?


--
You received this message because you are subscribed to the Google Groups "jDBI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jdbi/ea562101-c1bb-494a-965d-643a99940fe4n%40googlegroups.com.

Brian McCallister

unread,
Jun 7, 2021, 6:27:43 PM6/7/21
to jd...@googlegroups.com
Govinda, 

Question about the method:

```
@Transaction 
public void updateEmployee(Employee employee, Department dept) 
```

If this is the JDBI @Transaction annotation only works on a sql object method (declarative api). From the snippet, it looks like you might be annotating something other than dao interface, then invoking methods on that interface.

The way to do this which would work would be something like:

```
interface MyDao {
    @Transaction 
    public default void updateEmployee(Employee employee, Department dept) { 
        this.updateEmp(employee);          
        TimeUnit.SECONDS.sleep(90); // Pause 
        this.updateDepartment(dept) 
    }  
    
    @SqlUpdate("...")
    void updateEmp(Employee emp);

    @SqlUpdate("...")
    void updateDepartment(Department dept);
}

```

-Brian

On Sat, Jun 5, 2021 at 10:21 AM Govinda Sakhare <govindas...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages