Jboss JPA No Persistence provider for EntityManager named MyPersistence- EntityManager null
aliosha79 Sep 9, 2015 2:46 PMi'm working with Jboss WildFly 9.
I developed a module which aims to offer some DAO for persistence operation to different N other modules. Simply an X application should use it to write/read/update/delete on its own datasource specified by a JNDI name.
So the module is made up essentially of 2 package:
myapp.model and myapp.dao
i want the transaction to be handled by the JTA server layer so what i need is and EntityManager parametrized with datasource JNDI name.
In detail, a calling module: Module1 i have a function like this one:
private void doSomething (){
/************************************************************************/
MapGroup group = new MapGroup ();
group.setDescription("descrizione");
group.setExternalId(null);
group.setExternalLastSync(null);
group.setExternalRepository(null);
group.setIdGroup(995);
group.setName("gruppone");
IMapGroupDao mom = new MapGroupDaoKasImpl("java:jboss/datasources/KasOracleDS");
mom.addMapGroup(group);
MapGroup is my JPA annotated mapped Entity and resides in my JPA module together with it crud DAO implementation:
public EntityManagerFactory getEntityManagerFactory(String dataSourcePath) {
Properties properties = getProperties(dataSourcePath);
return Persistence.createEntityManagerFactory("MyPersistence", properties);
}
private Properties getProperties(String dataSourcePath) {
Properties properties = new Properties();
properties.put("javax.persistence.provider" ,"org.hibernate.jpa.HibernatePersistenceProvider");
properties.put("javax.persistence.jtaDataSource" ,dataSourcePath);
return properties;
}
The persistence.xml correctly placed in the META-INF directory has:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="MyPersistence" transaction-type="JTA" />
</persistence>
When i run module 1 i catch this exception:
00:36:36,374 WARN [org.hibernate.ejb.HibernatePersistence] (default task-3) HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
00:36:36,374 WARN [org.hibernate.ejb.HibernatePersistence] (default task-3) HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
00:36:36,374 WARN [org.hibernate.ejb.HibernatePersistence] (default task-3) HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
00:36:36,406 ERROR [org.keycloak.authentication.AuthenticationProcessor] (default task-3) failed authentication: javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyPersistence
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at com.klopotek.klas.auth.keycloak.persistence.dao.MapDao.getEntityManagerFactory(MapDao.java:19)
at com.klopotek.klas.auth.keycloak.persistence.dao.MapGroupDaoKasImpl.<init>(MapGroupDaoKasImpl.java:18)
at com.klopotek.klas.auth.keycloak.BaseKASFederationProvider.doSomething(BaseKASFederationProvider.java:593)
at com.klopotek.klas.auth.keycloak.BaseKASFederationProvider.validCredentials(BaseKASFederationProvider.java:516)
at org.keycloak.models.UserFederationManager.validCredentials(UserFederationManager.java:394)
at org.keycloak.authentication.authenticators.browser.AbstractFormAuthenticator.validatePassword(AbstractFormAuthenticator.java:176)
at org.keycloak.authentication.authenticators.browser.UsernamePasswordForm.validateForm(UsernamePasswordForm.java:46)
at org.keycloak.authentication.authenticators.browser.UsernamePasswordForm.action(UsernamePasswordForm.java:39)
at org.keycloak.authentication.DefaultAuthenticationFlow.processAction(DefaultAuthenticationFlow.java:59)
at org.keycloak.authentication.DefaultAuthenticationFlow.processAction(DefaultAuthenticationFlow.java:54)
at org.keycloak.authentication.AuthenticationProcessor.authenticationAction(AuthenticationProcessor.java:533)
at org.keycloak.services.resources.LoginActionsService.processFlow(LoginActionsService.java:306)
at org.keycloak.services.resources.LoginActionsService.processAuthentication(LoginActionsService.java:287)
at org.keycloak.services.resources.LoginActionsService.authenticateForm(LoginActionsService.java:333)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:140)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:103)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
at org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:59)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
this is my module configuration:
<module xmlns="urn:jboss:module:1.1" name="com.klopotek.klas.auth.kas-persistence-mapping">
<resources>
<resource-root path="kas-persistence-mapping-0.0.1-SNAPSHOT.jar"/>
</resources>
<dependencies>
<module name="javax.annotation.api"/>
<module name="javax.enterprise.api"/>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="org.hibernate" />
<module name="org.apache.commons.collections"/>
<module name="org.jboss.as.jpa.spi"/>
</dependencies>
</module>
I'm getting mad about solving this issue.
Where am i wrong?