| Sorry for the delay in responding, I didn't get a chance to take a look until this weekend. If I have correctly understood how the JNDI bindings works then it appears the method addListener in JNDIServiceImpl should first look up the context to which the session factory is bound, rather than trying to cast the InitialContext to an EventContext. So something like public void addListener(String jndiName, NamespaceChangeListener listener) { final InitialContext initialContext = buildInitialContext(); final Name name = parseName( jndiName, initialContext ); try { //If the jndiName is "java:jboss/SessionFactoryName" then name.get(0) will be "java:jboss" EventContext context = (EventContext) initialContext.lookup(name.get(0)); context.addNamingListener(name, EventContext.OBJECT_SCOPE, listener); } catch (Exception e) { throw new JndiException( "Unable to bind listener to namespace [" + name + "]", e ); } finally { cleanUp( initialContext ); } } I am unsure if getting the first element of the name is the correct approach and will always result in the context, however when debugging against EAP 6.4.2/ hibernate 4.2.x with this modification it did appear to successfully call the context.addNamingListener method. However it appears that the context is an instance of org.jboss.as.naming.WritableServiceBasedNamingStore which extends ServiceBasedNamingStore which has an empty implementation for addNamingListener, so the listener is never actually used. At a glance the code looks the same in Wildfly master, but I have not had time to debug yet. I believe the modification makes the code work as it was originally intended and I would imagine that in other situations (using other JNDI naming stores) it would allow the listener to work. |