IntelliJ JPA控制台无法在Tomcat(或数据库源)

时间:2017-01-20 16:08:14

标签: java jpa intellij-idea jndi

我已经设置了一个使用Tomcat的开发环境。为了启用多个数据环境,我已经使用JNDI来引用项目中的数据源。

但是,当我尝试在IntelliJ开发期间使用JPA控制台时,它出错:

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

这一关键功能是 JNDI service is disabled 。这很有意义,因为JNDI连接存储在Tomcat服务器上(server.xmlcontext.xml)。

我是否有办法在不将凭据存储到presistence.xml

的情况下使用这两种连接

我现在唯一能让它工作的方法是在评论和未注释的代码之间切换我的persistence.xml文件:

<?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.ooida.entities.TrumpiaList</class>
        <properties>
            <!-- For using hibernate with JNDI on Tomcat -->
            <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/AS400" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />

            <!-- For using hibernate with JNDI in the JPA/Hibernate Console -->
            <!--<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="user"/>-->
            <!--<property name="hibernate.connection.password" value="password"/>-->
        </properties>
    </persistence-unit>
</persistence>

0 个答案:

没有答案