JPA Hibernate updates an entity but there are no any changes in the DB

In short, I have three methods:

    @Transactional(propagation=Propagation.REQUIRED, noRollbackFor=Exception.class)
    public void Manage(long bookId) throws Exception {
    Book book = dao.getByKey(bookId);

    //...

    register(book);

}


@Transactional(propagation=Propagation.REQUIRED, noRollbackFor=Exception.class)
public void register(Book book) {

    try {

        // updateSomeId method should be called in another thread
        Runnable task = () -> {

            if(someId > 0) {
                dao.updateSomeId(book, someId);

        }
        Thread thread = new Thread(task);
        thread.start();
    } catch (Exception e) {

    }

}



@Transactional(propagation=Propagation.REQUIRED, noRollbackFor=Exception.class)
public void updateSomeId(Book book, long someId) {
    try {
        Book findedBook = getByKey(book.getBookId());
        findedBook.setSomeId(someId);
    } catch (Exception e) {
        logger.error("error", e);
    }
}

updateSomeId method must update the someId property in Book table.

In the log I see: Hibernate: update Book set author=?, someId=? where bookId=?

But, there are no any changes in my DB, no any errors. Could anyone explain what happens and how to solve it? It’s one of thousands of updates I have and only in this case it hasn’t updated the DB table.

JPA 2.1

Hibernate 5.2.10.Final

#java #spring #jpa #hibernate

3 Likes3.05 GEEK