简体   繁体   中英

Transaction attributes in lifecycle callback method of singleton session bean

Why methods annotated with @PostConstruct or @PreDestroy in singleton session beans with container managed transactions can have only one of the following transaction attributes:

• REQUIRED

• REQUIRES_NEW

• NOT_SUPPORTED

I guess because @PostConstruct or @PreDestroy annotated methods are methods invoked by the container during bean creation or destruction, so making these methods part of mandatory transaction wouldn't make sense (since there are no business methods called before @PostConstruct ). Same applies for SUPPORT type.

You can make the method transactional by itself (so this method becomes atomic) but it can't join other transactions because it is invoked by the container and you have no control over it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM