在运行Hibernate Hello World程序的时候,抛如下错误: view plain Exception in thread "main" org.hibernate.exception.LockAcquisitionException 解决方法

在运行Hibernate Hello World程序的时候,抛如下错误:
  1. Exception in thread "main" org.hibernate.exception.LockAcquisitionException : Could not open connection
  2. at org.hibernate.exception.internal.SQLStateConversionDelegate.convert( SQLStateConversionDelegate.java:144)
  3. at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert( StandardSQLExceptionConverter.java:49 )
  4. at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert( SqlExceptionHelper.java:125)
  5. at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert( SqlExceptionHelper.java:110)
  6. at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection( LogicalConnectionImpl.java:304)
  7. at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection( LogicalConnectionImpl.java:169)
  8. at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin( JdbcTransaction.java:67)
  9. at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin( AbstractTransactionImpl.java:160)
  10. at org.hibernate.internal.SessionImpl.beginTransaction( SessionImpl.java:1363)
  11. at com.ztesoft.hibernate.helloworld.StudentTest.main( StudentTest.java:25 )
  12. Caused by: java.sql.SQLException: The Network Adapter could not establish the connection
  13. at oracle.jdbc.driver.T4CConnection.logon( T4CConnection.java:412 )
  14. at oracle.jdbc.driver.PhysicalConnection.<init>( PhysicalConnection.java:531)
  15. at oracle.jdbc.driver.T4CConnection.<init>( T4CConnection.java:221 )
  16. at oracle.jdbc.driver.T4CDriverExtension.getConnection( T4CDriverExtension.java:32)
  17. at oracle.jdbc.driver.OracleDriver.connect( OracleDriver.java:503 )
  18. at java.sql.DriverManager.getConnection(Unknown Source)
  19. at java.sql.DriverManager.getConnection(Unknown Source)
  20. at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection( DriverManagerConnectionProviderImpl.java:192 )
  21. at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection( AbstractSessionImpl.java:278)
  22. at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection( LogicalConnectionImpl.java:297)
  23. ... 5 more
  24. Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
  25. at oracle.net.nt.ConnStrategy.execute( ConnStrategy.java:359 )
  26. at oracle.net.resolver.AddrResolution.resolveAndExecute( AddrResolution.java:422)
  27. at oracle.net.ns.NSProtocol.establishConnection( NSProtocol.java:672 )
  28. at oracle.net.ns.NSProtocol.connect( NSProtocol.java:237 )
  29. at oracle.jdbc.driver.T4CConnection.connect( T4CConnection.java:1042 )
  30. at oracle.jdbc.driver.T4CConnection.logon( T4CConnection.java:301 )
  31. ... 14 more
  32. Caused by: java.net.ConnectException: Connection refused: connect
  33. at java.net.PlainSocketImpl.socketConnect( Native Method )
  34. at java.net.PlainSocketImpl.doConnect(Unknown Source)
  35. at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
  36. at java.net.PlainSocketImpl.connect(Unknown Source)
  37. at java.net.SocksSocketImpl.connect(Unknown Source)
  38. at java.net.Socket.connect(Unknown Source)
  39. at oracle.net.nt.TcpNTAdapter.connect( TcpNTAdapter.java:141 )
  40. at oracle.net.nt.ConnOption.connect( ConnOption.java:123 )
  41. at oracle.net.nt.ConnStrategy.execute( ConnStrategy.java:337 )
  42. ... 19 more

通过plsql客户端发现oracle是可以连接的,为啥用hibernate来连接报连接拒绝呢? 
找了半天发现是 hibernate.cfg.xml

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  5. <hibernate-configuration>
  6. <session-factory>
  7. <!-- Database connection settings -->
  8. <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  9. <property name="connection.url">jdbc:oracle:thin:@localhost:1522:orcl</property>
  10. <property name="connection.username">scott</property>
  11. <property name="connection.password">tiger</property>
  12. <property name="dialect">
  13. org.hibernate.dialect.MySQLDialect
  14. </property>
  15. <property name="show_sql">true</property>
  16. <mapping resource="com/ztesoft/hibernate/helloworld/dto/Student.hbm.xml" />
  17. </session-factory>
  18. </hibernate-configuration>

配置文件中配置项

  1. <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>

配置的有问题,由于之前在本地安装过两个oracle实例,现在正用的oracle实例的监听端口为 1522,把上面的配置项中的监听端口1521改成1522就OK了

 
 
上一篇:2022/01/30


下一篇:年薪百万的程序员,30岁后送外卖、卖保险(1),retrofit和okhttp区别