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>
0
2 comments

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?


[2017-12-05 14:24:45] org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
[2017-12-05 14:24:45] org.hibernate.engine.jndi.JndiException: Error parsing JNDI name [java:jboss/datasources/RegisterDS]
[2017-12-05 14:24:45] java.lang.RuntimeException: javax.naming.NamingException: JNDI service is disabled
[2017-12-05 14:24:45] at com.intellij.execution.rmi.RemoteServer$Jndi.invoke(RemoteServer.java:139)
[2017-12-05 14:24:45] at com.sun.proxy.$Proxy4.getNameParser(Unknown Source)
[2017-12-05 14:24:45] at javax.naming.InitialContext.getNameParser(InitialContext.java:505)
[2017-12-05 14:24:45] at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:118)
[2017-12-05 14:24:45] at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:95)
[2017-12-05 14:24:45] at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:98)
[2017-12-05 14:24:45] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
[2017-12-05 14:24:45] at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
[2017-12-05 14:24:45] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
[2017-12-05 14:24:45] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
[2017-12-05 14:24:45] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
[2017-12-05 14:24:45] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
[2017-12-05 14:24:45] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
[2017-12-05 14:24:45] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
[2017-12-05 14:24:45] at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
[2017-12-05 14:24:45] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
[2017-12-05 14:24:45] at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
[2017-12-05 14:24:45] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
[2017-12-05 14:24:45] at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
[2017-12-05 14:24:45] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
[2017-12-05 14:24:45] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
[2017-12-05 14:24:45] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
[2017-12-05 14:24:45] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858)
[2017-12-05 14:24:45] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885)
[2017-12-05 14:24:45] at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
[2017-12-05 14:24:45] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
[2017-12-05 14:24:45] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
[2017-12-05 14:24:45] at com.intellij.jpa.remote.impl.JpaFacadeImpl.createEntityManagerFactory(JpaFacadeImpl.java:16)
[2017-12-05 14:24:45] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2017-12-05 14:24:45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[2017-12-05 14:24:45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[2017-12-05 14:24:45] at java.lang.reflect.Method.invoke(Method.java:498)
[2017-12-05 14:24:45] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
[2017-12-05 14:24:45] at sun.rmi.transport.Transport$1.run(Transport.java:200)
[2017-12-05 14:24:45] at sun.rmi.transport.Transport$1.run(Transport.java:197)
[2017-12-05 14:24:45] at java.security.AccessController.doPrivileged(Native Method)
[2017-12-05 14:24:45] at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
[2017-12-05 14:24:45] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
[2017-12-05 14:24:45] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
[2017-12-05 14:24:45] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
[2017-12-05 14:24:45] at java.security.AccessController.doPrivileged(Native Method)
[2017-12-05 14:24:45] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
[2017-12-05 14:24:45] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2017-12-05 14:24:45] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

Here is how my persistence.xml looks like after commenting out the JNDI source link

<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="xxx-unit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!--<jta-data-source>java:jboss/datasources/RegisterDS</jta-data-source>-->
<class>...</class>
<properties>
<property name="hibernate.show_sql" value = "false"/>
<property name="hibernate.generate_ddl" value = "false"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>

<property name="hibernate.query.factory_class" value="org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory"/>
<property name="hibernate.connection.charset" value="UTF-8"/>
<property name="javax.persistence.validation.mode" value="NONE"/>

<property name="hibernate.c3p0.min_size" value="2"/>
<property name="hibernate.c3p0.max_size" value="5"/>
<property name="hibernate.c3p0.timeout" value="600"/>
<property name="hibernate.c3p0.max_statements" value="0"/>
<property name="hibernate.c3p0.idle_test_period" value="300"/>
<property name="hibernate.c3p0.acquire_increment" value="1"/>

<property name="hibernate.order_updates" value="true"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="hibernate.jdbc.fetch_size" value="100"/>
<property name="hibernate.jdbc.batch_size" value="30"/>
<property name="hibernate.connection.release_mode" value="on_close"/>
<property name="hibernate.bytecode.use_reflection_optimizer" value="true"/>
<property name="hibernate.bytecode.provider" value="javassist"/>

<property name="hibernate.cache.use_second_level_cache" value="true"/>

<!-- for IDEA JPA Console -->
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@172.0.0.1:1521:xxxdb" />
<property name="javax.persistence.jdbc.user" value="LOGIN" />
<property name="javax.persistence.jdbc.password" value="PASS" />
</properties>
</persistence-unit>
</persistence>
0

Please sign in to leave a comment.