No Active Transaction after extending AuthenticationProvider

At first everything is fine with @Transactional and persistence.getEntityManager(). Then I extend the “LoginPasswordAuthenticationProvider” just like the doc says. Finally the “no active transaction” exception occurs. It’s ok if i use “persistence.createTransaction()” before getEntityManager but what happen?

Looking forward to your kindly reply!

java.lang.IllegalStateException: No active transaction
	at com.haulmont.cuba.core.sys.PersistenceImpl.getEntityManager(PersistenceImpl.java:170) ~[na:na]
	at com.haulmont.cuba.core.sys.PersistenceImpl.getEntityManager(PersistenceImpl.java:164) ~[na:na]
	at com.bocichina.zgbrowse.util.UtilServiceImpl.loginQueryUser(UtilServiceImpl.java:232) ~[na:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
	at com.haulmont.cuba.core.sys.remoting.LocalServiceInvokerImpl.invoke(LocalServiceInvokerImpl.java:94) ~[na:na]
	at com.haulmont.cuba.web.sys.remoting.LocalServiceProxy$LocalServiceInvocationHandler.invoke(LocalServiceProxy.java:159) ~[cuba-web-7.3.15.jar:7.3.15]
	at com.sun.proxy.$Proxy75.loginQueryUser(Unknown Source) ~[na:na]
	at com.bocichina.zgbrowse.web.sys.login.ExtAppLoginWindow.doLogin(ExtAppLoginWindow.java:121) ~[zgbrowse-web-1.jar:na]
	at com.haulmont.cuba.web.app.login.LoginScreen.doLogin(LoginScreen.java:243) [cuba-web-7.3.15.jar:7.3.15]
	at com.haulmont.cuba.web.app.login.LoginScreen.login(LoginScreen.java:213) [cuba-web-7.3.15.jar:7.3.15]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
	at com.haulmont.cuba.gui.xml.DeclarativeAction.actionPerform(DeclarativeAction.java:101) [cuba-gui-7.2.11.jar:7.2.11]
	at com.haulmont.cuba.web.gui.components.WebFrameActionsHolder.handleAction(WebFrameActionsHolder.java:160) [cuba-web-7.3.15.jar:7.3.15]
	at com.vaadin.event.ActionManager.handleAction(ActionManager.java:252) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.vaadin.event.ActionManager.handleActions(ActionManager.java:235) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.haulmont.cuba.web.widgets.CubaOrderedActionsLayout.changeVariables(CubaOrderedActionsLayout.java:88) [cuba-web-widgets-7.2.11.jar:na]
	at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:611) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:457) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:400) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:260) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:82) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1578) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:425) [vaadin-server-8.9.2-17-cuba.jar:8.9.2-17-cuba]
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:329) [cuba-web-7.3.15.jar:7.3.15]
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:215) [cuba-web-7.3.15.jar:7.3.15]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) [servlet-api.jar:4.0.FR]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:9.0.38]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.38]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.38]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.38]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.38]

Hi,
After briefly looking into the source code, I think that LoginPasswordAuthenticationProvider#authenticate method is always called during the active transaction, so you don’t need to start new transaction there even if you override the bean.

However, your screenshot and LoginPasswordAuthenticationProvider don’t correspond to the stack trace you’ve provided.
In this stack trace it is clearly seen that you are calling UtilServiceImpl.loginQueryUser() method directly from the UI (from ExtAppLoginWindow.doLogin()).
Fixing error from this stack trace requires you to add transaction management to the UtilServiceImpl.loginQueryUser() method.
It can be declarative (@Transactional) or manual (programmatic).
You can see good programmatic transaction management code examples here: Programmatic Transaction Management - CUBA Platform. Developer’s Manual

Hi Alex,
Thanks for your reply!
I may clearify current situation.
The loginQueryUser is like this:

And this method is always working fine until I add the to spring.xml to override the bean. I tried to override the AuthenticationManager in xml again and the method still doesn’t work.

As soon as I delete the declaration in spring.xml, the method ( along with other query methods) returns alright.

It really confuses me…

I would modify the code to use programmatic transaction management instead of the annotation. Probably it stops working in this place as a side effect, not sure why.