[jboss-user] [EJB 3.0] - entityManager is null
LGSW_Sam
do-not-reply at jboss.com
Wed Mar 7 08:59:00 EST 2007
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
More information about the jboss-user
mailing list