the JMX Component has the standard lifecycle methods: 
create(), start(),stop(), destroy()

My code looks like this:


  | @Service(objectName = "portal:service=SystemPropertyService")
  | @Management(SystemPropertyManagement.class)
  | @Local(SystemPropertyLocal.class)
  | @LocalBinding(jndiBinding = SystemPropertyLocal.JNDI)
  | public class SystemPropertyService implements SystemPropertyLocal,
  |             SystemPropertyManagement {
  | 
  |     private static final Log _log = LogFactory
  |                     .getLog(SystemPropertyService.class);
  | 
  |     private final ConcurrentHashMap<String, String> _properties = new 
ConcurrentHashMap<String, String>();
  | 
  |     
  |     @PersistenceContext(unitName = "portalEM")
  |     protected EntityManager em;
  | 
  | 
  |     public void create() throws Exception {
  |     }
  | 
  |     public void start() throws Exception {
  |             List<SystemProperty> properties = _getProperties();
  | 
  |             // add Properties
  |     }
  | 
  |     public void stop() {
  |             _properties.clear();
  |     }
  | 
  |     public void destroy() {
  |     }
  | 
  | 
  | 
  |     @SuppressWarnings("unchecked")
  |     @TransactionAttribute(TransactionAttributeType.REQUIRED)
  |     private List<SystemProperty> _getProperties() {
  |             try {
  | 
  |                     
  |                     List<SystemProperty> list = em.createQuery("from 
SystemProperty sp").getResultList();
  | 
  | 
  |                     em.flush();
  | 
  |                     return list;
  | 
  |             } catch (RuntimeException e) {
  |                     throw new SystemException(e);
  |             }
  | 
  |     }
  | }
  | 
I get a NullPointerException in _getProperties() because em is null. 


I would accept it if the EntityManager is not injected while constructor or 
create(), but why in start()? And why is this behaviour different since CR2?

The EntityManager is not injected before the start() method is completly 
processed. ( before: null, start(): null, after: injected)
In 4.0.4RC1 i can use the EntityManager in the start() method, 
in 4.0.4CR2 it is null (same Sourcecode). 
I also tried to inject only a datasource by @Resource and it was also not 
injected (but available by JNDI and InitialContext in start() method).
In both versions the EntityManager is available when the service is started.


This is a little bit curious. Do you have an explanation for this behaviour?

Regads

Peter


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

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


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to