I'm experimenting with Java EE 7, CDI, JPA and JSF.
When the webapp starts, I would like to run an initialization method in my CDI bean (marked with @PostConstruct) that does some work with the database (inserts some rows etc..). For this I need a transaction, but this wasn't as easy as I expected.
I have tried adding @Transactional annotation to my method, but apparently it only works with EJB. I actually tried converting my bean to EJB instead of CDI bean, but I still didn't get transaction to my @PostConstruct method. It worked with other methods in the bean, but not with my @PostConstruct initialization method.
Then I read about creating method interceptor to get transactions to CDI beans:
http://eubauer.de/kingsware/2012/01/16/cdi-and-transactions-e-g-in-jboss-7-0-2/
I tried this too, but no luck. It doesnt work either.
So how does one get transactions to a @PostConstruct initialization method in a CDI bean?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…