[EJB 3.0] - entityManager is null
by LGSW_Sam
Hi!
using jbossas 4.0.5.ga-ejb3 and hibernate 3.2.
I keep getting nullPointer exception with this class. I have checked that entityManager is null.
same kind of injecting the PersistenceContext works fine with several other classes..
I have tried without unitName but we have several persistence units so that wont work.
Can anyone help me to find the cause?
| package fi.logiasoftware.messageserver.services.backend;
|
| import java.util.List;
|
| import javax.ejb.Local;
| import javax.ejb.Remote;
| import javax.ejb.Stateless;
| import javax.ejb.TransactionAttribute;
| import javax.ejb.TransactionAttributeType;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| import org.jboss.annotation.ejb.LocalBinding;
| import org.jboss.annotation.ejb.RemoteBinding;
|
| import fi.logiasoftware.messageserver.config.ActionException;
| import fi.logiasoftware.messageserver.config.Destination;
|
| @Stateless
| @RemoteBinding(jndiBinding = "ActionExceptionHandling")
| @LocalBinding(jndiBinding = "ActionExceptionHandlingLocal")
| @Remote(ActionExceptionHandling.class)
| @Local(ActionExceptionHandling.class)
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public class ActionExceptionHandlingBean implements ActionExceptionHandling {
|
| @PersistenceContext(unitName = "MessageServer")
| private EntityManager entityManager;
|
| private ActionException ae;
| private List<ActionException> ActionExceptions;
|
| public void setActionException(String filename, Destination destination, String hash){
| ae = new ActionException();
| ae.setDestination(destination);
| ae.setFilename(filename);
| ae.setHash(hash);
| entityManager.persist(ae);
| }
|
|
| @SuppressWarnings("unchecked")
| public List<ActionException> getActionExceptions(){
| System.out.println("getActionExceptions ploo");
|
| if(entityManager != null) {
| ActionExceptions = entityManager.createQuery("from ActionException a order by a.id").getResultList();
| System.out.println("getActionExceptions loppuu");
| } else {
| System.out.println("entityManager on null");
| }
|
| return ActionExceptions;
| }
|
| public void removeActionException(ActionException a){
| entityManager.remove(a);
| }
|
| }
|
persistence.xml
| <persistence-unit name="MessageServer" transaction-type="jta">
|
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/MessageServicesDS</jta-data-source>
|
| <properties>
| <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
| <!-- property name="hibernate.hbm2ddl.auto" value="create"/ -->
| <property name="hibernate.session_factory_name" value="ServiceConfig"/>
| <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
| <property name="hibernate.jdbc.use_get_generated_keys" value="true"/>
| <property name="hibernate.order_updates" value="true"/>
| <property name="hibernate.jdbc.batch_versioned_data" value="true"/>
| <property name="jta.UserTransaction" value="UserTransaction"/>
| <property name="hibernate.current_session_context_class" value="jta"/>
| <property name="hibernate.query.jpaql_strict_compliance" value="false"/>
| <property name="hibernate.show_sql" value="false"/>
| <property name="hibernate.format_sql" value="true"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagerFactory"/>
| <property name="jboss.entity.manager.jndi.name" value="java:/EntityManager"/>
| <property name="hibernate.connection.release_mode" value="auto"/>
| <!-- property name="hibernate.cache.provider_class" value="org.hibernate.cache.OptimisticTreeCacheProvider"/ -->
| <!-- property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache"/ -->
| <!-- property name="hibernate.transaction.auto_close_session" value="true"/ -->
| <!-- property name="hibernate.cache.use_query_cache" value="true"/ -->
| </properties>
|
| <!-- property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml"/ -->
| </persistence-unit>
|
Br,
Sami Männistö
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4025792#4025792
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4025792
19Â years, 1Â month
[Beginners Corner] - service can't found classes
by xaleyba
Hi
I've a JBoss service as a .sar directory defined with the following structure:
|
| ./com/xx/activemq/mbean/service
| ./lib
| ./META-INF
|
|
I've all needed jars in lib directory and my jboss-service file is defined as follows:
|
| <!-- the SAR META-INF/jboss-service.xml descriptor -->
| <server>
| <loader-repository>
| com.notifications.broker.service:loader=activemq-broker-service.sar
| <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
| </loader-repository>
|
| <mbean code="com.xx.activemq.mbean.service.ActiveMQNetwork"
| name="jms.ActiveMQ:service=ActiveMQNetwork">
| <attribute name="PropertiesResource">remote-jndi.properties</attribute>
| <depends>jboss:service=Naming</depends>
| <depends>user:service=QuartzService,name=QuartzService</depends>
| </mbean>
|
| <!-- Proxy factory for MyService that will call target method on the target service -->
| <mbean code="org.jboss.invocation.jrmp.server.JRMPProxyFactory"
| name="jboss.jmx:type=adaptor,name=MyActiveMQNetworkInvokeTarget,protocol=jrmp,service=proxyFactory">
| <!-- Use the standard JRMPInvoker from conf/jboss-service.xxml -->
| <depends optional-attribute-name="InvokerName">jboss:service=invoker,type=jrmp</depends>
| <!-- The target MBean -->
| <depends optional-attribute-name="TargetName">jms.ActiveMQ:service=ActiveMQNetwork</depends>
| <!-- Where to bind the proxy factory -->
| <attribute name="JndiName">MyActiveMQNetworkInvokeTarget</attribute>
| <!-- Invoke target method instead of invoke(Invocation mi) -->
| <attribute name="InvokeTargetMethod">true</attribute>
| <!-- Comma-separated list of exported interfaces -->
| <attribute name="ExportedInterfaces">com.xx.activemq.mbean.service.ActiveMQNetworkMBean</attribute>
| <!-- client-side interceptors -->
| <attribute name="ClientInterceptors">
| <interceptors>
| <interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor>
| <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
| <interceptor>org.jboss.jmx.connector.invoker.client.InvokerAdaptorClientInterceptor</interceptor>
| <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>
| </interceptors>
| </attribute>
| </mbean>
|
| </server>
|
Everything worked well till I needed to isolate class loading adding loader-repository-config to the file. Now, when I start JBoss I got the message:
|
| 14:39:01,574 INFO [NamingService] Started jndi bootstrap jnpPort=1099, rmiPort=1098, backlog=50, bindAddress=/0.0.0.0, Client SocketFactory=null, Server SocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076
| 14:39:04,516 INFO [ServiceConfigurator] Problem configuring service jboss.jmx:type=adaptor,name=MyActiveMQNetworkInvokeTarget,protocol=jrmp,service=proxyFactory
| java.lang.IllegalArgumentException: Failed to find class: com.bs.activemq.mbean.service.ActiveMQNetworkMBean
| at org.jboss.util.propertyeditor.ClassArrayEditor.setAsText(ClassArrayEditor.java:38)
| at org.jboss.system.ServiceConfigurator.parseTextSerialData(ServiceConfigurator.java:541)
| at org.jboss.system.ServiceConfigurator.configure(ServiceConfigurator.java:311)
| at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:442)
| at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:153)
| at org.jboss.system.ServiceController.install(ServiceController.java:215)
| at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
| at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
| at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
| at $Proxy4.install(Lorg.w3c.dom.Element;Ljavax.management.ObjectName;)Ljava.util.List;(Unknown Source)
| at org.jboss.deployment.SARDeployer.create(SARDeployer.java:232)
| at org.jboss.deployment.MainDeployer.create(MainDeployer.java:935)
| at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:789)
| at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:753)
| at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
| at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
| at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
| at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
|
|
I counldn't understand why the service could not see my classes. (and I repeat, without the loader repository tag it wok well).
I've tried to solve it adding a tag but without success.
How could I solve the problem ?
Thanks in advance
C
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4025787#4025787
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4025787
19Â years, 1Â month