Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Getting a naming exception for a DataSource that I can find programatically(Internal Exception: javax.naming.NameNotFoundException: java:/comp/env/jdbc/MANDA)
Getting a naming exception for a DataSource that I can find programatically [message #1706662] Fri, 28 August 2015 13:06 Go to next message
Julie MacNaught is currently offline Julie MacNaughtFriend
Messages: 1
Registered: August 2015
Junior Member
I am using EclipseLink 2.5.2 with Liberty 8.5.5.5. This worked in the past with Tomcat 7.

I have a method that returns a ThreadLocal EntityManager that detects whether it is being run from a web container or a standalone java application. It tries to find a JNDI DataSource, but falls back to using a properties file if it cannot be found.

The problem is that the code finds the DataSource just fine, but then EclipseLink claims that it cannot be found.

Here's the stack, and I'll show the code after the stack.
[WARNING ] DSRA0174W: Warning: GenericDataStoreHelper is being used.
2015-08-28T08:40:45,047(Default Executor-thread-2) INFO : EMHandlerImpl.em: Got DataSource from JNDI
[EL Info]: 2015-08-28 08:40:45.163--ServerSession(84898271)--EclipseLink, version: Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd
[EL Severe]: ejb: 2015-08-28 08:40:45.179--ServerSession(84898271)--Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:/comp/env/jdbc/MANDA].
Internal Exception: javax.naming.NameNotFoundException: java:/comp/env/jdbc/MANDA
2015-08-28T08:40:45,180(Default Executor-thread-2) ERROR: EMHandlerImpl.em: Cannot create EntityManager
javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:/comp/env/jdbc/MANDA].
Internal Exception: javax.naming.NameNotFoundException: java:/comp/env/jdbc/MANDA
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:766) ~[?:?]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204) ~[?:?]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304) ~[?:?]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336) ~[?:?]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302) ~[?:?]
	at com.ibm.finance.portman.store.EMHandlerImpl.em(EMHandlerImpl.java:130) [?:1.4-SNAPSHOT]
	at com.ibm.finance.portman.store.MandaDaoImpl.em(MandaDaoImpl.java:98) [?:1.4-SNAPSHOT]
	at com.ibm.finance.portman.store.MandaDaoImpl.getUserByEmail(MandaDaoImpl.java:1000) [?:1.4-SNAPSHOT]
	at com.ibm.finance.portman.service.common.MandaRequestBase.<init>(MandaRequestBase.java:144) [?:1.4-SNAPSHOT]
	at com.ibm.finance.portman.service.GetUsersRequest.<init>(GetUsersRequest.java:10) [?:?]
	at com.ibm.finance.portman.service.UserService.getUsers(UserService.java:79) [?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
	at org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(InvokeMethodHandler.java:63) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandler.handleRequest(AbstractHandler.java:33) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.internal.handlers.CreateInvocationParametersHandler.handleRequest(CreateInvocationParametersHandler.java:54) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleResourceMethod(FindResourceMethodHandler.java:151) [?:1.4]
	at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:65) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.internal.handlers.FindRootResourceHandler.handleRequest(FindRootResourceHandler.java:95) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.internal.handlers.HeadMethodHandler.handleRequest(HeadMethodHandler.java:53) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.internal.handlers.OptionsMethodHandler.handleRequest(OptionsMethodHandler.java:46) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.internal.handlers.SearchResultHandler.handleRequest(SearchResultHandler.java:33) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.internal.log.ResourceInvocation.handleRequest(ResourceInvocation.java:92) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.internal.log.Requests.handleRequest(Requests.java:76) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26) [?:1.4]
	at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63) [?:1.4]
	at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:48) [?:1.4]
	at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:207) [?:1.4]
	at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154) [?:1.4]
	at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:119) [?:1.4]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) [com.ibm.ws.javaee.servlet.3.0_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1285) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:776) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:473) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:135) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71) [?:2.2]
	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:206) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:86) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:978) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1100) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4845) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.handleRequest(DynamicVirtualHost.java:297) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:981) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:262) [com.ibm.ws.webcontainer_1.0.8.jar:?]
	at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:955) [com.ibm.ws.transport.http_1.0.8.jar:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
Caused by: org.eclipse.persistence.exceptions.ValidationException: 
Exception Description: Cannot acquire data source [java:/comp/env/jdbc/MANDA].
Internal Exception: javax.naming.NameNotFoundException: java:/comp/env/jdbc/MANDA
	at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:520) ~[?:?]
	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109) ~[?:?]
	at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162) ~[?:?]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204) ~[?:?]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741) ~[?:?]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239) ~[?:?]
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685) ~[?:?]
	... 75 more
Caused by: javax.naming.NameNotFoundException: java:/comp/env/jdbc/MANDA
	at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLName.<init>(JavaURLName.java:84) ~[?:?]
	at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLNameParser.parse(JavaURLNameParser.java:40) ~[?:?]
	at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLNameParser.parse(JavaURLNameParser.java:61) ~[?:?]
	at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext$NameUtil.<init>(JavaURLContext.java:461) ~[?:?]
	at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:308) ~[?:?]
	at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:157) ~[?:?]
	at javax.naming.InitialContext.lookup(InitialContext.java:421) ~[?:1.8.0_45]
	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103) ~[?:?]
	at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162) ~[?:?]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204) ~[?:?]
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741) ~[?:?]
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239) ~[?:?]
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685) ~[?:?]
	... 75 more
2015-08-28T08:40:45,194(Default Executor-thread-2) ERROR: EMHandlerImpl.em: failed to initialize entity manager


Here's the code:
	public static EntityManager em()
	{
		if (emFactory == null) {
			LOG.debug("initializing entity-manager factory");
			Properties props = null;
			Context initCtx;
			try {
				// try getting it using just the name, and it will use the jndi service
				// this is when the data source is configured in the container
				initCtx = new InitialContext();
				Context envCtx = (Context) initCtx.lookup("java:comp/env"); 
				DataSource ds = (DataSource) envCtx.lookup("jdbc/MANDA");
				props = new Properties();
				props.setProperty("javax.persistence.nonJtaDataSource", "java:/comp/env/jdbc/MANDA");
				emFactory = (EntityManagerFactory) Persistence.createEntityManagerFactory(DB_NAME, props); 	
				LOG.info("Got DataSource from JNDI");
			} catch (Exception e) {
				// we may not be running in a container, so use properties to find the database
				try {
					props = getJPAProperties();
					emFactory = (EntityManagerFactory) Persistence.createEntityManagerFactory(DB_NAME, props);
					LOG.info("Configured data source from JPAProperties");
				} catch (Exception ex) {
					LOG.error("Exception getting properties", ex);
				}
			}
			if (emFactory == null) {
				LOG.error("No EntityManagerFactory created!");
			} else {
				LOG.debug("********EntityManagerFactory created");
			}
		}
		
		EntityManager entityManager = tlEntityManager.get();

		if (entityManager == null || ! entityManager.isOpen()) {
			LOG.debug("******** Creating EntityManager");
			try {
				entityManager = emFactory.createEntityManager();
				LOG.debug("********Entity manager created");
			} catch (Exception ex) {
				LOG.error("Cannot create EntityManager", ex);
			}
			
			if (entityManager != null)
			{
				if (LOG.isDebugEnabled()) {
					LOG.debug("<< Open " + entityManager.hashCode());
				}
				tlEntityManager.set(entityManager);
			}
			else
			{
				LOG.error("failed to initialize entity manager");
				tlEntityManager.set(null);
			}
		}
		return entityManager;
	}


This really has me stumped, so any suggestions are greatly appreciated.
Re: Getting a naming exception for a DataSource that I can find programatically [message #1707425 is a reply to message #1706662] Fri, 04 September 2015 15:38 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The logs should show you what server platform is being used, as that determines if it will use a string, compositeName or compoundName lookup on the context for the datasource. The default in ServerPlatform is to use a CompositeName, while the WebSpherePlatform class specifies it should use a string lookup which your test shows works. Try specifying the target server as WebSphere_Liberty_Platform using:
<property name="eclipselink.target-server" value="WebSphere_Liberty"/>

http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_target_server.htm
Previous Topic:Entity Update throws NPE for @ElementColection of Map - Eclipselink 2.5.2
Next Topic:Lazy loading is not triggered in front-end, though static weaving is enabled
Goto Forum:
  


Current Time: Sat Oct 12 19:10:14 GMT 2024

Powered by FUDForum. Page generated in 0.03372 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top