Error parsing JNDI name in Persistence Console
Answered
I've set up JNDI to work with the local Tomcat instance I use when debugging and for production.
However, I also would like to work on queries inside of the Persistence Console.
I have to choose either-or, not both in order to make things work correctly.
Is there a way I can utilize the JNDI connection configured in Tomcat to connect inside of the Console for Persistence pane?
Error in console looks like this:
[2017-01-30 12:03:44] org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
[2017-01-30 12:03:44] org.hibernate.engine.jndi.JndiException: Error parsing JNDI name [java:comp/env/jdbc/AS400]
[2017-01-30 12:03:44] java.lang.RuntimeException: javax.naming.NamingException: JNDI service is disabled
[2017-01-30 12:03:44] at com.intellij.execution.rmi.RemoteServer$Jndi.invoke(RemoteServer.java:148)
[2017-01-30 12:03:44] at com.sun.proxy.$Proxy4.getNameParser(Unknown Source)
[2017-01-30 12:03:44] at javax.naming.InitialContext.getNameParser(InitialContext.java:505)
[2017-01-30 12:03:44] at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:118)
[2017-01-30 12:03:44] at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:95)
[2017-01-30 12:03:44] at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:98)
[2017-01-30 12:03:44] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
[2017-01-30 12:03:44] at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
[2017-01-30 12:03:44] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
[2017-01-30 12:03:44] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
[2017-01-30 12:03:44] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
[2017-01-30 12:03:44] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
[2017-01-30 12:03:44] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
[2017-01-30 12:03:44] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257)
[2017-01-30 12:03:44] at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
[2017-01-30 12:03:44] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
[2017-01-30 12:03:44] at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
[2017-01-30 12:03:44] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
[2017-01-30 12:03:44] at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
[2017-01-30 12:03:44] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
[2017-01-30 12:03:44] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
[2017-01-30 12:03:44] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
[2017-01-30 12:03:44] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858)
[2017-01-30 12:03:44] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885)
[2017-01-30 12:03:44] at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
[2017-01-30 12:03:44] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
[2017-01-30 12:03:44] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
[2017-01-30 12:03:44] at com.intellij.jpa.remote.impl.JpaFacadeImpl.createEntityManagerFactory(JpaFacadeImpl.java:16)
[2017-01-30 12:03:44] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2017-01-30 12:03:44] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[2017-01-30 12:03:44] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[2017-01-30 12:03:44] at java.lang.reflect.Method.invoke(Method.java:498)
[2017-01-30 12:03:44] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
[2017-01-30 12:03:44] at sun.rmi.transport.Transport$1.run(Transport.java:200)
[2017-01-30 12:03:44] at sun.rmi.transport.Transport$1.run(Transport.java:197)
[2017-01-30 12:03:44] at java.security.AccessController.doPrivileged(Native Method)
[2017-01-30 12:03:44] at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
[2017-01-30 12:03:44] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
[2017-01-30 12:03:44] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
[2017-01-30 12:03:44] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
[2017-01-30 12:03:44] at java.security.AccessController.doPrivileged(Native Method)
[2017-01-30 12:03:44] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
[2017-01-30 12:03:44] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[2017-01-30 12:03:44] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[2017-01-30 12:03:44] at java.lang.Thread.run(Thread.java:745)
When my persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="Messaging">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.example.Class</class>
<properties>
<!--<property name="hibernate.connection.url" value="jdbc:as400://SERVER:PORT"/>-->
<!--<property name="hibernate.connection.driver_class" value="com.ibm.as400.access.AS400JDBCDriver"/>-->
<!--<property name="hibernate.connection.username" value="username"/>-->
<!--<property name="hibernate.connection.password" value="password"/>-->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.connection.datasource" value="java:comp/env/jdbc/AS400" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
</properties>
</persistence-unit>
</persistence>
I must comment-out the connection.datasource property, and un-comment the traditional connection properties to get it to work in the Persistence Console:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="Messaging">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.example.Class</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:as400://SERVER:PORT"/>
<property name="hibernate.connection.driver_class" value="com.ibm.as400.access.AS400JDBCDriver"/>
<property name="hibernate.connection.username" value="username"/>
<property name="hibernate.connection.password" value="password"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<!--<property name="hibernate.connection.datasource" value="java:comp/env/jdbc/AS400" />-->
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
</properties>
</persistence-unit>
</persistence>
Please sign in to leave a comment.
It appears to be a known issue, please follow https://youtrack.jetbrains.com/issue/IDEA-166656.
Is there a way to avoid this problem using JPA+Hibernate+Wilfly 10? I've tried to comment out jta-data-source and uncomment direct hibernate connection settings, but this doesn't help, I get such an error trying to make a request in JPA Console. I don't know where does it get the JNDI name when it's commented in persistence.xml, is it possible that the JPA Console uses the cached version of persistence.xml file?
Here is how my persistence.xml looks like after commenting out the JNDI source link