简体   繁体   English

无法为事务打开 Hibernate Session; 嵌套异常是无法打开连接

[英]Could not open Hibernate Session for transaction; nested exception is Could not open connection

enter image description here在此处输入图像描述

I created an application with spring + hibernate, but I always get this error.我用 spring + hibernate 创建了一个应用程序,但我总是得到这个错误。 This is my first application with hibernate, I read some guides but I can not solve this problem.这是我第一个使用休眠的应用程序,我阅读了一些指南,但我无法解决这个问题。 Where am I doing wrong?我在哪里做错了?

This is the code of my application这是我的应用程序的代码

4.0.0 com.gss css_pos_mvn 0.0.1-SNAPSHOT war CSS Point of Sale 4.0.0 com.gss css_pos_mvn 0.0.1-SNAPSHOT 战争 CSS 销售点

    <properties>
        <jsf2.version>2.2.14</jsf2.version>
        <spring.version>4.3.10.RELEASE</spring.version>
        <hibernate.version>4.3.6.Final</hibernate.version>
    </properties>


    <dependencies>
        <!-- JSF Dep. -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>prenter code hereimefaces</artifactId>
            <version>6.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>${jsf2.version}</version>enter code here
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>${jsf2.version}</version>
        </dependency>
        <!-- Spring Dep. -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Spring ORM support -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc11 
            <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc11</artifactId> 
            <version>21.5.0.0</version> </dependency> -->

        
    <!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc6 -->
<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.4</version>
</dependency>



    </dependencies>

    <build>
        <finalName>Clever-Software-Solutions-POS</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>strong text

Hibernate休眠

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- MySQL database -->
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <!-- show SQL in console -->
        <property name="hibernate.show_sql">true</property>
        <!-- readable format for SQL output in the console -->
        <property name="format_sql">true</property>
        
        
        
        <mapping package="com.css.pos.domain.*"/>
        <mapping class="com.css.pos.domain.BusinessLine"/>
        <mapping class="com.css.pos.domain.Company"/>
        
          
            
        
    </session-factory>
</hibernate-configuration>

Spring Configuration弹簧配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">
    <context:component-scan base-package="com.css.pos"></context:component-scan>
    <!-- support spring annotation -->
    <context:annotation-config />
    <!-- support annotation transaction -->
    <tx:annotation-driven transaction-manager="transactionManager" />
 
    <!-- declare datasource -->
        <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl21"/>
        <property name="username" value="c##gss_pos" />
        <property name="password" value="sys" />
    </bean>
 
    <!--Hibernate session factory configuration -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- load hibernate configuration file -->
        <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
        <!-- where to find the ORM classes -->
        <property name="packagesToScan" value="com.roytuts.hibernate.model" />
    </bean>
 
    <!-- Transaction manager -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    
    
</beans>

Based on your information, it need your check on your oracle jdbc connection first, especially for below part:根据您的信息,首先需要检查您的 oracle jdbc 连接,尤其是以下部分:

<!-- declare datasource -->
    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl21"/>
    <property name="username" value="c##gss_pos" />
    <property name="password" value="sys" />
</bean>

You need ensure you can connect to your Oracle DB via the localhost:1521:orcl21 with proper user and password.您需要确保您可以使用正确的用户名和密码通过 localhost:1521:orcl21 连接到您的 Oracle 数据库。

Can you also use the latest JDBC driver?您还可以使用最新的 JDBC 驱动程序吗? You are using 11.2.0.4.您正在使用 11.2.0.4。 Try using 21.5.0.0 or 19.14.0.0.尝试使用 21.5.0.0 或 19.14.0.0。 Check out OTN page.查看OTN页面。

暂无
暂无

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

相关问题 无法打开 Hibernate Session 进行事务; 嵌套异常是 org.hibernate.exception.JDBCConnectionException:无法打开连接 - Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection 休眠会话无法打开进行交易 - Hibernate Session Could not open for transaction 无法打开 Hibernate Session 进行事务; 嵌套异常是 org.hibernate.exception - Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception CannotCreateTransactionException:无法打开休眠会话进行事务 - CannotCreateTransactionException: Could not open Hibernate Session for transaction 无法为事务打开Hibernate Session,JavaConfig - Could not open Hibernate Session for transaction, JavaConfig 为什么会发生这种“无法打开Hibernate Session进行交易”的情况? - why this “Could not open Hibernate Session for transaction” occured? 首次登录时无法为事务打开休眠会话 - Could not open Hibernate Session for transaction on First Login 无法打开连接休眠 - Could not open connection hibernate org.springframework.transaction.CannotCreateTransactionException:无法打开Hibernate Session进行事务处理 - org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction CannotCreateTransactionException:无法打开事务的Hibernate会话(Hibernate,MySQL,MVC) - CannotCreateTransactionException: Could not open Hibernate Session for transaction(Hibernate, MySQL, MVC)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM