spring - @Transactional on @PostConstruct method -


i want read text data fixtures (csv files) @ start on application , put in database.

for that, have created populationservice initialization method (@postconstruct annotation).

i want them executed in single transaction, , hence added @transactional on same method.

however, @transactional seems ignored : transaction started / stopped @ low level dao methods.

do need manage transaction manually ?

this might helpful (http://forum.springsource.org/showthread.php?58337-no-transaction-in-transactional-service-called-from-postconstruct):

in @postconstruct (as afterpropertiesset initializingbean interface) there no way ensure post processing done, (indeed) there can no transactions. way ensure that working using transactiontemplate.

so if in @postconstruct executed within transaction have this:

@service("something") public class {      @autowired     @qualifier("transactionmanager")     protected platformtransactionmanager txmanager;      @postconstruct     private void init(){         transactiontemplate tmpl = new transactiontemplate(txmanager);         tmpl.execute(new transactioncallbackwithoutresult() {             @override             protected void dointransactionwithoutresult(transactionstatus status) {                 //put call service here             }         });    } } 

Comments