简体   繁体   English

WebLogic错误:无法获取JDBC连接

[英]WebLogic error: Unable to acquire JDBC Connection

I have a strange exception with WebLogic 12.2.1.3, Hibernate 5.3, Sprnig Data JPA, and Java EE. 对于WebLogic 12.2.1.3,Hibernate 5.3,Sprnig Data JPA和Java EE,我有一个奇怪的例外。

I have a database, and a Generic JDBC Data source in weblogic, with the JNDI name of jdbc/UsersDS. 我在weblogic中有一个数据库和一个通用JDBC数据源,其JNDI名称为jdbc/UsersDS.

When I'm trying to list the entries in it, I get a really long exception, which I don't really want to paste in here, so I used Pastebin: Here it is . 当我尝试列出其中的条目时,我遇到了一个很长的异常,我真的不想在这里粘贴,所以我使用了Pastebin: 这是 Pls let me know, if I should instead paste it here anyway. 请让我知道,如果我还是应该将其粘贴在这里。

I have the exact same setup for this artefact, then what I have for another one, which connects to the same server, but to a different database, with different user. 对于此工件,我具有完全相同的设置,对于另一工件,我具有相同的设置,该连接到同一服务器,但使用不同的用户连接到不同的数据库。 That one works like a charm, this one doesn't. 一个像魅力一样起作用,而这个不一样。 The only difference I can think of being related to this is the fact that the artefact, where I get the error from has Spring Data Redis included as a dependency alongside Spring Data JPA. 我能想到的与此有关的唯一区别是这样的事实,在我得到错误的工件中,Spring Data Redis与Spring Data JPA一起作为依赖项包含在内。

Persistence.xml: persistence.xml中:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
             version="2.2">
    <persistence-unit name="UsersDS" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/UsersDS</jta-data-source>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.transaction.factory_class"
                      value="org.hibernate.transaction.JTATransactionFactory"/>
            <property name="hibernate.transaction.manager_lookup_class" value="javax.transaction.TransactionManager"/>
            <property name="hibernate.transaction.jta.platform" value="Weblogic"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
        </properties>
    </persistence-unit>
</persistence>

Ui.: One more thing that might be related to the problem is because I have both Spring Data JPA and Redis on the classpath, I had to mark the JpaRepository interface as a @NoRepositoryBean , because I'd get a duplicate otherwise. Ui .:可能与此问题有关的另一件事是,因为我在类路径上同时具有Spring Data JPA和Redis,所以我不得不将JpaRepository接口标记为@NoRepositoryBean ,因为否则我会得到一个副本。 So I have a method to produce the CDI Repository Bean: 因此,我有一种生成CDI存储库Bean的方法:

    @Inject
    private EntityManager entityManager;

    @Produces
    @RequestScoped
    public UserRepository userRepository() {
        return createRepository(UserRepository.class);
    }

    private <T extends Repository> T createRepository(Class<T> repositoryClass) {
        RepositoryFactorySupport factory = new JpaRepositoryFactory(entityManager);
        return factory.getRepository(repositoryClass);
    }

UI2.: I also wrote some integration tests with a H2 in memory database and everything runs smoothly UI2:我还用内存数据库中的H2编写了一些集成测试,一切运行顺利

I have the solution, and it's probably some workaround, or sg, but I have nothing else. 我有解决方案,可能是一些解决方法或sg,但我别无选择。

So what happened, was I had (by default) in the weblogic datasource global transactions on. 所以发生了什么事,(默认情况下)我在weblogic数据源中进行了全局事务处理。 Switching it off solved the problem 关闭它可以解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM