`

org.hibernate.exception.LockAcquisitionException : Could not open connection

 
阅读更多
在运行Hibernate Hello World程序的时候,抛如下错误:
Exception in thread "main" org.hibernate.exception.LockAcquisitionException : Could not open connection
       at org.hibernate.exception.internal.SQLStateConversionDelegate.convert( SQLStateConversionDelegate.java:144)
       at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert( StandardSQLExceptionConverter.java:49 )
       at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert( SqlExceptionHelper.java:125)
       at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert( SqlExceptionHelper.java:110)
       at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection( LogicalConnectionImpl.java:304)
       at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection( LogicalConnectionImpl.java:169)
       at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin( JdbcTransaction.java:67)
       at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin( AbstractTransactionImpl.java:160)
       at org.hibernate.internal.SessionImpl.beginTransaction( SessionImpl.java:1363)
       at com.ztesoft.hibernate.helloworld.StudentTest.main( StudentTest.java:25 )
Caused by: java.sql.SQLException: The Network Adapter could not establish the connection
       at oracle.jdbc.driver.T4CConnection.logon( T4CConnection.java:412 )
       at oracle.jdbc.driver.PhysicalConnection.<init>( PhysicalConnection.java:531)
       at oracle.jdbc.driver.T4CConnection.<init>( T4CConnection.java:221 )
       at oracle.jdbc.driver.T4CDriverExtension.getConnection( T4CDriverExtension.java:32)
       at oracle.jdbc.driver.OracleDriver.connect( OracleDriver.java:503 )
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection( DriverManagerConnectionProviderImpl.java:192 )
       at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection( AbstractSessionImpl.java:278)
       at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection( LogicalConnectionImpl.java:297)
       ... 5 more
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
       at oracle.net.nt.ConnStrategy.execute( ConnStrategy.java:359 )
       at oracle.net.resolver.AddrResolution.resolveAndExecute( AddrResolution.java:422)
       at oracle.net.ns.NSProtocol.establishConnection( NSProtocol.java:672 )
       at oracle.net.ns.NSProtocol.connect( NSProtocol.java:237 )
       at oracle.jdbc.driver.T4CConnection.connect( T4CConnection.java:1042 )
       at oracle.jdbc.driver.T4CConnection.logon( T4CConnection.java:301 )
       ... 14 more
Caused by: java.net.ConnectException: Connection refused: connect
       at java.net.PlainSocketImpl.socketConnect( Native Method )
       at java.net.PlainSocketImpl.doConnect(Unknown Source)
       at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
       at java.net.PlainSocketImpl.connect(Unknown Source)
       at java.net.SocksSocketImpl.connect(Unknown Source)
       at java.net.Socket.connect(Unknown Source)
       at oracle.net.nt.TcpNTAdapter.connect( TcpNTAdapter.java:141 )
       at oracle.net.nt.ConnOption.connect( ConnOption.java:123 )
       at oracle.net.nt.ConnStrategy.execute( ConnStrategy.java:337 )
       ... 19 more


通过plsql客户端发现oracle是可以连接的,为啥用hibernate来连接报连接拒绝呢?
找了半天发现是 hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1522:orcl</property>
    <property name="connection.username">scott</property>
    <property name="connection.password">tiger</property>

  
    <property name="dialect">
        org.hibernate.dialect.MySQLDialect
    </property>


    <property name="show_sql">true</property>

    <mapping resource="com/ztesoft/hibernate/helloworld/dto/Student.hbm.xml" />
    
</session-factory>
</hibernate-configuration>

配置文件中配置项
 <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
配置的有问题,由于之前在本地安装过两个oracle实例,现在正用的oracle实例的监听端口为 1522,把上面的配置项中的监听端口1521改成1522就OK了
分享到:
评论

相关推荐

    org.hibernate.HibernateException: No Hibernate Session bound to thread

    Hibernate Session 绑定线程解决方案 在 Java web 开发中, Hibernate 是一个非常流行的 ORM(Object-Relational Mapping)框架,用于将 Java 对象映射到关系数据库中。然而,在使用 Hibernate 进行数据库操作时,...

    weblogic12 下 org.hibernate.hql.ast.HqlToken

    ### WebLogic 12下org.hibernate.hql.ast.HqlToken冲突解决方案 在使用WebLogic 12部署应用程序时,可能会遇到与`org.hibernate.hql.ast.HqlToken`相关的异常问题。这种异常通常与Hibernate版本之间的不兼容性有关...

    HIbernate4.3.6整合c3p0所需jar

    Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.connection.C3P0ConnectionProvider] at org.hibernate.engine.jdbc.connections.internal....

    org.springframework.orm.hibernate3.LocalSessionFactoryBean

    hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); hibernateProperties.setProperty("hibernate.show_sql", "true"); sessionFactory.setHibernateProperties...

    com.microsoft.sqlserver.jdbc.SQLServerException: 只进结果集不支持请求的操作 解决方案

    这可以通过在Hibernate配置文件中设置`hibernate.connection.autocommit`属性为`false`,并在查询前手动设置事务,然后通过`Session`的`createSQLQuery()`或`createQuery()`方法附加`ResultSet.TYPE_SCROLL_...

    org.hibernate.ejb-library-3.4.0.GA-A

    标题 "org.hibernate.ejb-library-3.4.0.GA-A" 指示这是一个与Hibernate相关的库,特别针对EJB(Enterprise JavaBeans)版本3.4.0,并且是为OSGi环境优化的。描述中提到它适用于在Virgo Jetty服务器上进行Web开发,...

    解决SpringDataJPA报错:org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null w

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/...

    Could not roll back Hibernate transaction.doc

    nested exception is org.hibernate.TransactionException: JDBC rollback failed 这表明Hibernate事务回滚操作失败,导致事务不能正确回滚。 二、问题原因 该问题的主要原因是手动对数据库做了些操作,导致...

    hibernate-jpa-2.1-api-1.0.2.Final-API文档-中英对照版.zip

    Maven坐标:org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final; 标签:hibernate、javax、persistence、jpa、api、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开...

    org.hibernate.ejb-library-3.4.0.GA

    标题中的"org.hibernate.ejb-library-3.4.0.GA"是Hibernate Entity Beans的一个特定版本,它是Hibernate框架的一部分,专门用于处理Java Enterprise Edition (EE)环境中的持久化。Hibernate是著名的对象关系映射...

    Hibernate不同数据库的连接及SQL方言

    Hibernate提供了多种SQL方言,例如org.hibernate.dialect.OracleDialect、org.hibernate.dialect.MySQLDialect、org.hibernate.dialect.SQLServerDialect等。我们可以在配置文件中使用元素来设置SQL方言,例如: ...

    HIbernate4.3.6-c3p0所需jar.rar

    Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.connection.C3P0ConnectionProvider] as strategy [org.hibernate.engine.jdbc.... ...

    hibernate.properties

    #hibernate.connection.provider_class org.hibernate.connection.DriverManagerConnectionProvider #hibernate.connection.provider_class org.hibernate.connection.DatasourceConnectionProvider #hibernate....

    hibernate-jpa-2.1-api-1.0.2.Final-API文档-中文版.zip

    Maven坐标:org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final; 标签:hibernate、javax、persistence、jpa、api、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index...

    hibernate(api 介绍).pdf

    提供了各种实现类,例如 org.hibernate.type.PrimitiveType Class、org.hibernate.type.DateType Class 和 org.hibernate.type.BinaryType Class 等。 可扩展接口 1. org.hibernate.dialect.Dialect abstract_...

    hibernate.5.1.0.jar全部

    包含hibernate所有所需jar包还有一些其他包日志包、jpa支持包等: 列如:hibernate-core-5.1.0.Final.jar hibernate-ehcache-5.1.0.Final.jar hibernate-entitymanager-5.1.0.Final.jar hibernate-envers-5.1.0....

    org.hibernate.jpa.QueryHints jar包

    org.hibernate.jpa.QueryHints jar hibernate-entitymanager-4.3.0.Final.jar

    hibernate-validator 5.3.5.Final jar

    hibernate-validator 5.3.5.Final jar包 ;desc:if you want validator your project

    关键字user附近有语法错误解决方案

    警告: SQL Error: 156, ...org.hibernate.exception.SQLGrammarException: could not execute query org.hibernate.util.JDBCExceptionReporter logExceptions 严重: 关键字 'user' 附近有语法错误。 的解决方案。

    启动tomcat报错org.hibernate.cache.CacheProvider

    标题中的“启动tomcat报错org.hibernate.cache.CacheProvider”指的是在尝试启动Apache Tomcat服务器时遇到了与Hibernate缓存提供者相关的错误。这通常涉及到Hibernate框架的配置或运行时环境问题。Hibernate是一个...

Global site tag (gtag.js) - Google Analytics