Problems retrieving EnityManagerFactory in an stateless EJB Bean
up vote
0
down vote
favorite
I'm having difficulties to persist UserEntitys on my JavaDB from an ejb Project. I tried a couple of solutions from various google searches but non seem to help me.
I'm using GlassFish 4 and the JavaDB which comes with it.
This is my Statlessbean which needs the EntityManager
It should be injected by the container through @PersistenceContext as far as I understand.
@Stateless
public class UserManagementBean implements UserManagementLocal, UserManagementRemote {
@PersistenceContext(unitName = "ChatDB")
private EntityManager entityManager;
@EJB
private ChatManagementLocal chatManagement;
@EJB
private StatisticManagementLocal statisticManagement;
//...
@Override
public void login(String username, String password) throws Exception {
//...
}
@Override
public void logout(String username) {
//...
}
@Override
public void registerUser(String username, String password) throws Exception {
TypedQuery<UserEntity> query = entityManager.createNamedQuery("UserEntity.singleUser", UserEntity.class);
query.setParameter("username", username);
UserEntity foundUser;
try {
foundUser = query.getSingleResult();
} catch (NoResultException e) {
foundUser = new UserEntity();
foundUser.setLoggedIn(false);
foundUser.setUsername(username);
foundUser.setPassword(generateHash(password));
entityManager.persist(foundUser);
chatManagement.sendRegisterMessage(username);
}
throw new Exception("Der Benutzername ist bereits vergeben.");
}
public String generateHash(String password { ... }
}
project-ejb
--META-INF
----persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="ChatDB" transaction-type="JTA">
<jta-data-source>java:app/jdbc/ChatDB</jta-data-source>
<jar-file>Chat-common.jar</jar-file>
<properties>
<property name="eclipselink.target-database" value="Derby"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
project-ear
--META-INF
----glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC
"-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
"http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool name="ChatDBPool"
res-type="javax.sql.ConnectionPoolDataSource"
datasource-classname="org.apache.derby.jdbc.ClientDataSource">
<property name="serverName" value="localhost" />
<property name="port" value="1527" />
<property name="databaseName" value="chat" />
<property name="connectionAttributes" value=";create=true"></property>
<property name="user" value="APP" />
<property name="password" value="APP" />
</jdbc-connection-pool>
<jdbc-resource enabled="true"
jndi-name="java:app/jdbc/ChatDB"
pool-name="ChatDBPool" />
</resources>
Console
javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:752)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:702)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:507)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at com.sun.proxy.$Proxy286.registerUser(Unknown Source)
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:498)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName ChatDB
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:544)
at de.fh_dortmund.inf.cw.chat.server.beans.UserManagementBean.registerUser(UserManagementBean.java:146)
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:498)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
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:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:205)
... 19 more
At this point I have no idea on how to start on this issue, what have I missed? What should I check? What further details do you need?
jpa java-ee ejb entitymanager
|
show 2 more comments
up vote
0
down vote
favorite
I'm having difficulties to persist UserEntitys on my JavaDB from an ejb Project. I tried a couple of solutions from various google searches but non seem to help me.
I'm using GlassFish 4 and the JavaDB which comes with it.
This is my Statlessbean which needs the EntityManager
It should be injected by the container through @PersistenceContext as far as I understand.
@Stateless
public class UserManagementBean implements UserManagementLocal, UserManagementRemote {
@PersistenceContext(unitName = "ChatDB")
private EntityManager entityManager;
@EJB
private ChatManagementLocal chatManagement;
@EJB
private StatisticManagementLocal statisticManagement;
//...
@Override
public void login(String username, String password) throws Exception {
//...
}
@Override
public void logout(String username) {
//...
}
@Override
public void registerUser(String username, String password) throws Exception {
TypedQuery<UserEntity> query = entityManager.createNamedQuery("UserEntity.singleUser", UserEntity.class);
query.setParameter("username", username);
UserEntity foundUser;
try {
foundUser = query.getSingleResult();
} catch (NoResultException e) {
foundUser = new UserEntity();
foundUser.setLoggedIn(false);
foundUser.setUsername(username);
foundUser.setPassword(generateHash(password));
entityManager.persist(foundUser);
chatManagement.sendRegisterMessage(username);
}
throw new Exception("Der Benutzername ist bereits vergeben.");
}
public String generateHash(String password { ... }
}
project-ejb
--META-INF
----persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="ChatDB" transaction-type="JTA">
<jta-data-source>java:app/jdbc/ChatDB</jta-data-source>
<jar-file>Chat-common.jar</jar-file>
<properties>
<property name="eclipselink.target-database" value="Derby"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
project-ear
--META-INF
----glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC
"-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
"http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool name="ChatDBPool"
res-type="javax.sql.ConnectionPoolDataSource"
datasource-classname="org.apache.derby.jdbc.ClientDataSource">
<property name="serverName" value="localhost" />
<property name="port" value="1527" />
<property name="databaseName" value="chat" />
<property name="connectionAttributes" value=";create=true"></property>
<property name="user" value="APP" />
<property name="password" value="APP" />
</jdbc-connection-pool>
<jdbc-resource enabled="true"
jndi-name="java:app/jdbc/ChatDB"
pool-name="ChatDBPool" />
</resources>
Console
javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:752)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:702)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:507)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at com.sun.proxy.$Proxy286.registerUser(Unknown Source)
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:498)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName ChatDB
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:544)
at de.fh_dortmund.inf.cw.chat.server.beans.UserManagementBean.registerUser(UserManagementBean.java:146)
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:498)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
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:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:205)
... 19 more
At this point I have no idea on how to start on this issue, what have I missed? What should I check? What further details do you need?
jpa java-ee ejb entitymanager
2
If it cannot instantiate a JPA provider then either the persistence.xml is not found, or the persistence-unit is not found, or the JPA provider jars are not found. That's all there is
– Billy Frost
Nov 22 at 9:01
@BillyFrost Where would I check for the exact reason why it failed to retrieve?
– D. McDermott
Nov 22 at 9:03
dont assume "it" will tell you the exact reason. You'll have to inspect your deployment and checks each of those things, and compare with what the docs for that JavaEE server says for use of JPA
– Billy Frost
Nov 22 at 9:31
So I created this project structure via the Eclipse Project Wizard, is this in general the right place for the .xml files?
– D. McDermott
Nov 22 at 9:54
2
Check the spelling of your persistence.xml file. It is incorrect in at least one place above, where it is spelt with ...ance.
– Steve C
Nov 23 at 1:49
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm having difficulties to persist UserEntitys on my JavaDB from an ejb Project. I tried a couple of solutions from various google searches but non seem to help me.
I'm using GlassFish 4 and the JavaDB which comes with it.
This is my Statlessbean which needs the EntityManager
It should be injected by the container through @PersistenceContext as far as I understand.
@Stateless
public class UserManagementBean implements UserManagementLocal, UserManagementRemote {
@PersistenceContext(unitName = "ChatDB")
private EntityManager entityManager;
@EJB
private ChatManagementLocal chatManagement;
@EJB
private StatisticManagementLocal statisticManagement;
//...
@Override
public void login(String username, String password) throws Exception {
//...
}
@Override
public void logout(String username) {
//...
}
@Override
public void registerUser(String username, String password) throws Exception {
TypedQuery<UserEntity> query = entityManager.createNamedQuery("UserEntity.singleUser", UserEntity.class);
query.setParameter("username", username);
UserEntity foundUser;
try {
foundUser = query.getSingleResult();
} catch (NoResultException e) {
foundUser = new UserEntity();
foundUser.setLoggedIn(false);
foundUser.setUsername(username);
foundUser.setPassword(generateHash(password));
entityManager.persist(foundUser);
chatManagement.sendRegisterMessage(username);
}
throw new Exception("Der Benutzername ist bereits vergeben.");
}
public String generateHash(String password { ... }
}
project-ejb
--META-INF
----persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="ChatDB" transaction-type="JTA">
<jta-data-source>java:app/jdbc/ChatDB</jta-data-source>
<jar-file>Chat-common.jar</jar-file>
<properties>
<property name="eclipselink.target-database" value="Derby"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
project-ear
--META-INF
----glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC
"-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
"http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool name="ChatDBPool"
res-type="javax.sql.ConnectionPoolDataSource"
datasource-classname="org.apache.derby.jdbc.ClientDataSource">
<property name="serverName" value="localhost" />
<property name="port" value="1527" />
<property name="databaseName" value="chat" />
<property name="connectionAttributes" value=";create=true"></property>
<property name="user" value="APP" />
<property name="password" value="APP" />
</jdbc-connection-pool>
<jdbc-resource enabled="true"
jndi-name="java:app/jdbc/ChatDB"
pool-name="ChatDBPool" />
</resources>
Console
javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:752)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:702)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:507)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at com.sun.proxy.$Proxy286.registerUser(Unknown Source)
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:498)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName ChatDB
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:544)
at de.fh_dortmund.inf.cw.chat.server.beans.UserManagementBean.registerUser(UserManagementBean.java:146)
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:498)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
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:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:205)
... 19 more
At this point I have no idea on how to start on this issue, what have I missed? What should I check? What further details do you need?
jpa java-ee ejb entitymanager
I'm having difficulties to persist UserEntitys on my JavaDB from an ejb Project. I tried a couple of solutions from various google searches but non seem to help me.
I'm using GlassFish 4 and the JavaDB which comes with it.
This is my Statlessbean which needs the EntityManager
It should be injected by the container through @PersistenceContext as far as I understand.
@Stateless
public class UserManagementBean implements UserManagementLocal, UserManagementRemote {
@PersistenceContext(unitName = "ChatDB")
private EntityManager entityManager;
@EJB
private ChatManagementLocal chatManagement;
@EJB
private StatisticManagementLocal statisticManagement;
//...
@Override
public void login(String username, String password) throws Exception {
//...
}
@Override
public void logout(String username) {
//...
}
@Override
public void registerUser(String username, String password) throws Exception {
TypedQuery<UserEntity> query = entityManager.createNamedQuery("UserEntity.singleUser", UserEntity.class);
query.setParameter("username", username);
UserEntity foundUser;
try {
foundUser = query.getSingleResult();
} catch (NoResultException e) {
foundUser = new UserEntity();
foundUser.setLoggedIn(false);
foundUser.setUsername(username);
foundUser.setPassword(generateHash(password));
entityManager.persist(foundUser);
chatManagement.sendRegisterMessage(username);
}
throw new Exception("Der Benutzername ist bereits vergeben.");
}
public String generateHash(String password { ... }
}
project-ejb
--META-INF
----persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="ChatDB" transaction-type="JTA">
<jta-data-source>java:app/jdbc/ChatDB</jta-data-source>
<jar-file>Chat-common.jar</jar-file>
<properties>
<property name="eclipselink.target-database" value="Derby"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
project-ear
--META-INF
----glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC
"-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
"http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool name="ChatDBPool"
res-type="javax.sql.ConnectionPoolDataSource"
datasource-classname="org.apache.derby.jdbc.ClientDataSource">
<property name="serverName" value="localhost" />
<property name="port" value="1527" />
<property name="databaseName" value="chat" />
<property name="connectionAttributes" value=";create=true"></property>
<property name="user" value="APP" />
<property name="password" value="APP" />
</jdbc-connection-pool>
<jdbc-resource enabled="true"
jndi-name="java:app/jdbc/ChatDB"
pool-name="ChatDBPool" />
</resources>
Console
javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:752)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:702)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:507)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at com.sun.proxy.$Proxy286.registerUser(Unknown Source)
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:498)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName ChatDB
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:544)
at de.fh_dortmund.inf.cw.chat.server.beans.UserManagementBean.registerUser(UserManagementBean.java:146)
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:498)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
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:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:205)
... 19 more
At this point I have no idea on how to start on this issue, what have I missed? What should I check? What further details do you need?
jpa java-ee ejb entitymanager
jpa java-ee ejb entitymanager
edited Nov 21 at 23:37
asked Nov 21 at 22:01
D. McDermott
687
687
2
If it cannot instantiate a JPA provider then either the persistence.xml is not found, or the persistence-unit is not found, or the JPA provider jars are not found. That's all there is
– Billy Frost
Nov 22 at 9:01
@BillyFrost Where would I check for the exact reason why it failed to retrieve?
– D. McDermott
Nov 22 at 9:03
dont assume "it" will tell you the exact reason. You'll have to inspect your deployment and checks each of those things, and compare with what the docs for that JavaEE server says for use of JPA
– Billy Frost
Nov 22 at 9:31
So I created this project structure via the Eclipse Project Wizard, is this in general the right place for the .xml files?
– D. McDermott
Nov 22 at 9:54
2
Check the spelling of your persistence.xml file. It is incorrect in at least one place above, where it is spelt with ...ance.
– Steve C
Nov 23 at 1:49
|
show 2 more comments
2
If it cannot instantiate a JPA provider then either the persistence.xml is not found, or the persistence-unit is not found, or the JPA provider jars are not found. That's all there is
– Billy Frost
Nov 22 at 9:01
@BillyFrost Where would I check for the exact reason why it failed to retrieve?
– D. McDermott
Nov 22 at 9:03
dont assume "it" will tell you the exact reason. You'll have to inspect your deployment and checks each of those things, and compare with what the docs for that JavaEE server says for use of JPA
– Billy Frost
Nov 22 at 9:31
So I created this project structure via the Eclipse Project Wizard, is this in general the right place for the .xml files?
– D. McDermott
Nov 22 at 9:54
2
Check the spelling of your persistence.xml file. It is incorrect in at least one place above, where it is spelt with ...ance.
– Steve C
Nov 23 at 1:49
2
2
If it cannot instantiate a JPA provider then either the persistence.xml is not found, or the persistence-unit is not found, or the JPA provider jars are not found. That's all there is
– Billy Frost
Nov 22 at 9:01
If it cannot instantiate a JPA provider then either the persistence.xml is not found, or the persistence-unit is not found, or the JPA provider jars are not found. That's all there is
– Billy Frost
Nov 22 at 9:01
@BillyFrost Where would I check for the exact reason why it failed to retrieve?
– D. McDermott
Nov 22 at 9:03
@BillyFrost Where would I check for the exact reason why it failed to retrieve?
– D. McDermott
Nov 22 at 9:03
dont assume "it" will tell you the exact reason. You'll have to inspect your deployment and checks each of those things, and compare with what the docs for that JavaEE server says for use of JPA
– Billy Frost
Nov 22 at 9:31
dont assume "it" will tell you the exact reason. You'll have to inspect your deployment and checks each of those things, and compare with what the docs for that JavaEE server says for use of JPA
– Billy Frost
Nov 22 at 9:31
So I created this project structure via the Eclipse Project Wizard, is this in general the right place for the .xml files?
– D. McDermott
Nov 22 at 9:54
So I created this project structure via the Eclipse Project Wizard, is this in general the right place for the .xml files?
– D. McDermott
Nov 22 at 9:54
2
2
Check the spelling of your persistence.xml file. It is incorrect in at least one place above, where it is spelt with ...ance.
– Steve C
Nov 23 at 1:49
Check the spelling of your persistence.xml file. It is incorrect in at least one place above, where it is spelt with ...ance.
– Steve C
Nov 23 at 1:49
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
This:
project-ejb
--META-INF
----persistance.xml
looks suspicious.
You appear to have mis-spelt "persistence.xml".
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
This:
project-ejb
--META-INF
----persistance.xml
looks suspicious.
You appear to have mis-spelt "persistence.xml".
add a comment |
up vote
2
down vote
accepted
This:
project-ejb
--META-INF
----persistance.xml
looks suspicious.
You appear to have mis-spelt "persistence.xml".
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
This:
project-ejb
--META-INF
----persistance.xml
looks suspicious.
You appear to have mis-spelt "persistence.xml".
This:
project-ejb
--META-INF
----persistance.xml
looks suspicious.
You appear to have mis-spelt "persistence.xml".
answered Nov 29 at 1:09
Steve C
13.9k41930
13.9k41930
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421073%2fproblems-retrieving-enitymanagerfactory-in-an-stateless-ejb-bean%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
If it cannot instantiate a JPA provider then either the persistence.xml is not found, or the persistence-unit is not found, or the JPA provider jars are not found. That's all there is
– Billy Frost
Nov 22 at 9:01
@BillyFrost Where would I check for the exact reason why it failed to retrieve?
– D. McDermott
Nov 22 at 9:03
dont assume "it" will tell you the exact reason. You'll have to inspect your deployment and checks each of those things, and compare with what the docs for that JavaEE server says for use of JPA
– Billy Frost
Nov 22 at 9:31
So I created this project structure via the Eclipse Project Wizard, is this in general the right place for the .xml files?
– D. McDermott
Nov 22 at 9:54
2
Check the spelling of your persistence.xml file. It is incorrect in at least one place above, where it is spelt with ...ance.
– Steve C
Nov 23 at 1:49