Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDI Transactions warnings

Tags:

java

jpa

cdi

after calling a method, which is working with database (JPA) I am getting warnings:

@Named    
public class SomeClass{
    
@PersistenceContext(unitName = "jpaLayer")
private EntityManager entityManager;
        .....
        .....
    @Transactional
    public T save(T entity) {
            entityManager.persist(entity);
            return entity;
    }
}

Managed bean with Transactional annotation and TxType of REQUIRED called outside a transaction context. Beginning a transaction...

But then its generating SQL query and everything is OK.

Info: Hibernate: insert into ALL_USERS_EXMPL (DATE_ADDED, login, password) values (?, ?, ?)

How can I get rid of these warnings?

like image 869
Vovan Avatar asked Mar 12 '26 17:03

Vovan


1 Answers

Use REQUIRES_NEW instead of REQUIRED to run it outside a transaction context. Please refer to docs

you need to have @Transactional(Transactional.TxType.REQUIRES_NEW)

like image 195
user3487063 Avatar answered Mar 15 '26 07:03

user3487063



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!