Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to create sessionFactory object.org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect

Tags:

java

hibernate

I try to connect to the database, which is on remote server. I use jdk 1.7.0_60, Hibernate-release-4.3.5 final. In project are included following jars:

antlr-2.7.7.jar;
dom4j-1.6.1.jar,

hibernate-commons-annotations-4.04.Final.jar,
hibernate-core-4.3.5.Final.jar, hibernate-entitymanager-4.3.5.Final.jar, javassist-3.18.1-GA.jar, jboss-logging-3.1.3.GA.jar, jboss-logging-annotations-1.2.0.Beta1.jar,jboss-transaction-api_1.2_spec-1.0.0.Final.jar, mysql-connector-java-5.1.30-bin.jar.

the exception is following:

Jun 14, 2014 7:31:56 PM  org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
Jun 14, 2014 7:31:56 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
Jun 14, 2014 7:31:56 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jun 14, 2014 7:31:56 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jun 14, 2014 7:31:56 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: swmhibernate.cfg.xml
Jun 14, 2014 7:31:56 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: swmhibernate.cfg.xml
Jun 14, 2014 7:31:56 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jun 14, 2014 7:31:57 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jun 14, 2014 7:31:57 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL   [jdbc:mysql://sopro.informatik.uni-augsburg.de:3306/team02]
Jun 14, 2014 7:31:57 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=team02, password=****, autocommit=false}
Jun 14, 2014 7:31:57 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Jun 14, 2014 7:31:57 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Failed to create sessionFactory object.org.hibernate.exception.JDBCConnectionException:   Error calling Driver#connect
Exception in thread "main" java.lang.ExceptionInInitializerError
at de.swm.hibernate.Funktionen.main(Funktionen.java:25)
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:118)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at de.swm.hibernate.Funktionen.main(Funktionen.java:22)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2539)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2321)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)
... 14 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 27 more

The configuration-file is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-  configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- connecting to the database --> 
<property 

name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property 

name="hibernate.connection.url">jdbc:mysql://host:3306/team02</property> 
<property name="connection.username">name</property>
<property name="connection.password">****** </property>  


<property name="connection.pool_size">1</property>

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

 <property name="hibernate.connection.autocommit">false</property>
 <property name="show_sql">true</property>
 <property name="format_sql">true</property>
 <property name="use_sql_comments">true</property>
 <property name="hbm2ddl.auto">update</property>
 <!-- for jdbc transaction -->
 <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

 <!-- mapping file -->
 <mapping class="de.swm.hibernate.Address"/>
 <mapping class="de.swm.hibernate.Plant"/>
 <mapping class="de.swm.hibernate.Plantprocessinfo"/>
 <mapping class="de.swm.hibernate.User"/>
 <mapping class="de.swm.hibernate.Directmarketing"/>
 <mapping class="de.swm.hibernate.Account"/>
 <mapping class="de.swm.hibernate.Customer"/>
 <mapping class="de.swm.hibernate.Report"/>
 <mapping class="de.swm.hibernate.Mrl"/>
 <mapping class="de.swm.hibernate.Srl"/>
 <mapping class="de.swm.hibernate.MrlmarketingInfo"/>
 <mapping class="de.swm.hibernate.Srl_outputpreis"/>
  <mapping class="de.swm.hibernate.Srl_workprice"/>
 <mapping class="de.swm.hibernate.InvoiceMailingaddress"/>

</session-factory>

How can I solve this problem?

like image 810
user3697542 Avatar asked Jun 14 '14 17:06

user3697542


2 Answers

The problem is with mysql-connector-java-5.1.30-bin.jar. Replace it with mysql-connector-java-5.0.8-bin.jar . It will solve that exception .

like image 77
Trilok Singh Devda Avatar answered Nov 13 '22 16:11

Trilok Singh Devda


Please make sure that the database server is up and running.Looks like the server is not responding, as there are no packets received and timeout is happening.

like image 6
zerocool Avatar answered Nov 13 '22 15:11

zerocool