Dear bro. I met this exception with springboot 1.5.3 + hibernate5.
And ,i used the @EnableTransactionManagement
at the start application class. Have the transaction aop configuration as follow code…
@Aspect
@Configuration
public class TransactionManagerConfig {
private static final String AOP_POINTCUT_EXPRESSION="execution (* *..service..*Service*.*(..))";
@Autowired
@Qualifier("transactionManager")
private HibernateTransactionManager transactionManager;
......
......
It worked very nice until yestardy.And then,i create a service named c.a.b.service.MessageCoreService.
@Service
public class MessageCoreService {
@Autowired
private MessageSourceResolverMapper mapper;
@Autowired
private TenantIdentifierResolver tir;
public Map<String, MsgDetail> fetchCode(String code, Locale locale) {
System.err.println("Thread.currentThread().getName() at MessageCoreService:" + Thread.currentThread().getName());
System.err.println("request teanantId:" + tir.resolveCurrentTenantIdentifier());
System.err.println("locale3 at MessageCoreService:" + locale.toString());
MsgDetail enMsg = mapper.resolveCode(code, MessageSourceResolver.DEFAULT_LOCALE);
MsgDetail localeMsg = mapper.resolveCode(code, locale.toString());
Map<String, MsgDetail> ret = new HashMap<String, MsgDetail>();
ret.put("defaultLocale", enMsg);
ret.put("requestLocale", localeMsg);
return ret;
}
In the controller, do a test first.
@Autowired
private MessageCoreService msgService;
@RequestMapping("/test")
@ResponseBody
public Map<String, MsgDetail> test() {
System.err.println("111111111111111111111111111111111:");
TenantIdentifierResolver.tempOverideTenantId(ZAppUtils.getInitDatabaseId()); // change to init database
ServiceResult<Module> rslt = new ServiceResult<Module>();
Locale locale = new Locale("en", "US");
System.err.println("Thread.currentThread().getName() at ResourcesModuleController:" + Thread.currentThread().getName());
System.err.println("request teanantId:" + tir.resolveCurrentTenantIdentifier());
return msgService.fetchCode("e90001.5", locale);
Then, the hibernate exception “Could not obtain transaction-synchronized Session for current thread” occured.
I checked over and over,everything is ok.But it’s aways occured.
I don’t understand any of this. And then,i coped c.a.b.service.MessageCoreService. to c.a.c.service.MessageAdminService. Yes,just change a direcory,rename it.
In the controller,add a method.
@Autowired
private MessageCoreAdminService msgAdminService;
@RequestMapping("/test2")
@ResponseBody
public Map<String, MsgDetail> test2() {
System.err.println("111111111111111111111111111111111:");
TenantIdentifierResolver.tempOverideTenantId(ZAppUtils.getInitDatabaseId()); // change to init database
ServiceResult<Module> rslt = new ServiceResult<Module>();
Locale locale = new Locale("en", "US");
System.err.println("Thread.currentThread().getName() at ResourcesModuleController:" + Thread.currentThread().getName());
return msgAdminService.fetchCode("e90001.5", locale);
}
And then ,an incredible scene appeared. When i access the test2,it worked normally, but the test method ,it still show me the “transaction-synchronized Session” exception. Oh ,I feel like I’m breaking down. I can’t resolve the problem.
Pls help.