AnsweredAssumed Answered

Accessing jndi in activiti

Question asked by chilopoda on Dec 9, 2013
Latest reply on Dec 11, 2013 by chilopoda
I have a problem when accessing jndi in activiti. I have read the articles : and but still no success. We use hibernate with the jpa specification for our project. I'm able to execute hibernate queries when using Java Service Task, also I'm able to achieve the same from a Task Listener this way:

private BeanManager getBeanManager() {
try {
return (BeanManager) InitialContext.doLookup("java:comp/BeanManager");
catch (final NamingException e) {
return null;

private T lookup(final Class clazz) {
final BeanManager bm = getBeanManager();
final Iterator> iter = bm.getBeans(clazz).iterator();
if (!iter.hasNext()) {
throw new IllegalStateException("CDI BeanManager cannot find an instance of requested type " + clazz.getName());
final Bean bean = (Bean);
final CreationalContext ctx = bm.createCreationalContext(bean);
return (T) bm.getReference(bean, clazz, ctx);

and getting the entitymanager this way:

EntityManagerFactory emf = null;
EntityManager em = null;
BeanManager bm = getBeanManager();
emf = lookup(EntityManagerFactory.class);
System.out.println("Contents of emf ::::"+emf);
em = emf.createEntityManager();

With the entity manager in place i can then execute hibernate statements and queries.

Now the problem comes in when i try the same after a trigger from a timer event e.g the timeCycle, i'm not able to access the jndi.
The exception i get is : javax.naming.NameNotFoundException: java:comp/BeanManager. We do not use spring for our application.
My config file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

  <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    <property name="dataSourceJndiName" value="java:comp/BeanManager" />
    <property name="transactionsExternallyManaged" value="true" />
    <property name="history" value="audit" /> 
    <property name="jobExecutorActivate" value="true" />
    <property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:xe" />
    <property name="jdbcDriver" value="oracle.jdbc.driver.OracleDriver" />
    <property name="jdbcUsername" value="fm" />
    <property name="jdbcPassword" value="fm123" />
    <property name="databaseSchemaUpdate" value="true" />

Any help is highly appreciated. Thank you good people.