[jboss-user] [EJB] - EntityManager in jmx.MBean

MarcusDidiusFalco do-not-reply at jboss.com
Thu Dec 10 07:58:57 EST 2009


I need to use the EntityManager inside an JMX MBean


  | <?xml version="1.0" encoding="UTF-8" ?>
  | <persistence>
  |   <persistence-unit name="bafoeg3sked">
  |     <jta-data-source>java:/bafoeg21DS</jta-data-source>
  |     <properties>
  |       <property name="hibernate.hbm2ddl.auto" value="update"/>
  |      
  |       <property name="jboss.entity.manager.jndi.name" value="java:/bafoeg3EntityManagerSKED" />
  |     </properties>
  |   </persistence-unit>
  | </persistence>
  | 


  | Context ctx;
  | try {
  | 	ctx = (Context) new InitialContext();
  | 	em = (EntityManager) ctx.lookup("java:/bafoeg3EntityManagerSKED");
  | } catch (NamingException e) {
  | 	log.error(e);
  | }
  | 
At this point the EntityManager is not null

org.jboss.ejb3.entity.TransactionScopedEntityManager at 7663a6

However at

  | Query query = em.createNamedQuery("findGruppeByValue");
  | 

I get the following exception:

  | java.lang.NullPointerException
  |         at org.jboss.ejb3.entity.ManagedEntityManagerFactory.getNonTxEntityManag
  | er(ManagedEntityManagerFactory.java:59)
  |         at org.jboss.ejb3.entity.ManagedEntityManagerFactory.getTransactionScope
  | dEntityManager(ManagedEntityManagerFactory.java:164)
  |         at org.jboss.ejb3.entity.TransactionScopedEntityManager.createNamedQuery
  | (TransactionScopedEntityManager.java:139)
  |         at bafoeg21.scheduler.util.SchedulerConfig.buildSkedStore(SchedulerConfi
  | g.java:522)
  | 

Any ideas what might be the cause?

Thanks,

Hans

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4269978#4269978

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4269978



More information about the jboss-user mailing list