java - Propagation.REQUIRES_NEW seems to not work -


using spring (mvc, batch, , persistence) have following piece of interface defined:

public interface jobstatusservice {   @transactional(readonly = false)   @modifying   jobstatus save(jobstatus status);    @transactional(readonly = true, propagation = propagation.requires_new)   optional<jobstatus> get(resultsidentifier identifier); } 

note requires_new it's on broken method.

this interface implemented in:

@override public jobstatus save(jobstatus status) {     if (status.getuserid() == null) {         status.setuserid(userservice.getcurrentuser());     }     status.setlastupdatetime(new date());     return repository.save(status); }  @override public optional<jobstatus> get(resultsidentifier identifier) {     return repository.findbyjobidentifier(identifier); } 

where repository jpa repository following:

public interface jobstatusrepository extends repository<jobstatus, resultsidentifier> {    jobstatus save(jobstatus status);    optional<jobstatus> findbyjobidentifier(resultsidentifier id); } 

resultsidentifier simple compound id class of string code , id number.

elsewhere, have batch writer finishing out writing jobstatus repository, , web controller class runs loop containing query job status service. save() operation seems execute correctly, , get() operation works right the first time.

however, if first run of loop calls get() , jobstatus isn't "complete" on subsequent runs still not "complete". , in fact same exact object comes hibernate (which persistence tool under hood). what's happening session cache in sessionimpl/statefulpersistencecontext keeping copy of , returning instead of doing real database query. so, figured, propagation = propagation.requires_new should start new transaction/session, right? same problem recurs whether include in annotation or not.

are life-cycles of session , transaction not coterminous here? if not, how can tell spring want start new session? i'm trying avoid changing xml configs push hibernate session factory jobstatusservice implementation , manually clear() it, no other part of system sees hibernate directly.

i'm happy hear suggestions debugging session-related stuff, given in code it's magic annotation.

i "solved" setting fetch eager on particular entity definition. doesn't seem should work, put in this question inquire might have happened.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -