-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: java.io.EOFException: Can not read response from server
PostPosted: Wed Sep 23, 2009 9:59 am 
Newbie

Joined: Tue Sep 22, 2009 4:34 am
Posts: 4
I have a programm, which uses a database on one server to make write operations and a replication of this database is used for reading operations, situated on another server. if I execute a write operation and then a read operation there is thrown the exception posted below.
If I excute my programm only using the write operation or only the read operation, there are no problems, only by switching the server during my running application.
I hope somebody can help me...I already tried very much to solve the problem, but nothing works right now

thank you

Hallo,
ich habe ein programm geschrieben, dass eine datenbank zum schreiben benutzt und eine replikation dieser datenbank zum lesen. Beide sind auf verschiedenen servern. wenn ich connection pools benutze, erhalte ich die exception. Ohne connection pools, läuft mein programm ohne probleme. wenn ich die schreib oder leseoperation allein durchführe, gibt es auch keinerlei probleme.
ich hoffe jemand kann mir helfen...ich habe schon viel recherchiert, aber leider noch keine lösung dafür gefunden...vielen dank

the exception:
Code:
org.hibernate.exception.GenericJDBCException: could not load an entity: [mainpackage.Person#67]
   at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
   at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1269)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:139)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:124)
   at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
   at mainpackage.Main.readEntries(Main.java:55)
   at mainpackage.Main.main(Main.java:29)
Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

STACKTRACE:

java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
   at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1997)
   at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2411)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1448)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
   at org.hibernate.loader.Loader.doQuery(Loader.java:363)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1255)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:139)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:124)
   at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
   at mainpackage.Main.readEntries(Main.java:55)
   at mainpackage.Main.main(Main.java:29)


** END NESTED EXCEPTION **



Last packet sent to the server was 4 ms ago.
   at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2622)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1448)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
   at org.hibernate.loader.Loader.doQuery(Loader.java:363)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1255)
   ... 13 more
Exception in thread "main" org.hibernate.TransactionException: JDBC rollback failed
   at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:142)
   at mainpackage.Main.readEntries(Main.java:72)
   at mainpackage.Main.main(Main.java:29)
Caused by: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:888)
   at com.mysql.jdbc.Connection.getMutex(Connection.java:3728)
   at com.mysql.jdbc.Connection.rollback(Connection.java:5204)
   at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:134)
   ... 2 more


my main.java
Code:
package mainpackage;


import java.util.List;
import java.io.IOException;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;


public class Main
{
   
   public static void main(String[] args) throws IOException, InterruptedException
   {
      Configuration confRead      = new Configuration();
      SessionFactory sfRead       = confRead.configure("topology3/hibernateRead.cfg.xml").buildSessionFactory();
      confRead    = null;
      
      Configuration confWrite      = new Configuration();
      SessionFactory sfWrite    = confWrite.configure("topology3/hibernateWrite.cfg.xml").buildSessionFactory();
      confWrite    = null;

      
      insertTestPerson( sfWrite ,100 );
      readEntries( sfRead );
      
   }
   
   public static void readEntries( SessionFactory sfRead ) throws IOException
   {
   
      //random value for id
      int randomID;
      
      for( int index = 0; index < 80; index++ )
      {
         randomID = (int)Math.floor( ( Math.random() * 100 ) + 1 );
         
         Session session    = null;
         Transaction tx       = null;
         
         Person person = new Person();
         
         try
         {
            session = sfRead.openSession();
            
            
            tx = session.beginTransaction();
            person = (Person)session.get(Person.class, randomID);
            if( person != null )
            {
               List<Address> addresses = (List)person.getAddresses();
               person.getName();
            }
            else
            {
               System.out.println("NULL" + randomID);
            }
            
            tx.commit();
            
         }
         catch (Exception e)
         {
            e.printStackTrace();
            tx.rollback();
         }
         finally
         {
            session.close();
            session = null;
         }
      }
      
      System.out.println("[Method]::readEntries()");
   }
   
   public static void insertPerson( SessionFactory sfWrite, Person person )
   {

      
      Session session    = null;
      Transaction tx       = null;
      
      try
      {
         session = sfWrite.openSession();
         tx       = session.beginTransaction();
         
         session.save( person ); // Person & Address -> DB
         tx.commit();
      }
      catch (Exception e)
      {
         e.printStackTrace();
         tx.rollback();
      }
      finally
      {
         session.close();
         session = null;
      }
   }
   
   public static void insertTestPerson( SessionFactory sfWrite, int number )
   {
      for( int i = 0; i < number; i++ )
      {
         Address address = new Address();
         address.setZip("0000");
         address.setCity("NOWHERE");
         
         Person person = new Person();
         person.setName("NOBODY");
         person.addAddress( address );
         
         insertPerson( sfWrite, person );
      }
      System.out.println("[Method]::insertTestPerson()");
   }
   
}



the configuration files
hibernateWrite.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://188.40.80.213/test_replication_db</property>
      <property name="hibernate.connection.username">user</property>
      <property name="hibernate.connection.password">pw</property>
      <!-- property name="hibernate.connection.pool_size">0</property-->
      <property name="show_sql">false</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.hbm2ddl.auto">create</property>
     
     
                 <property name="hibernate.c3p0.min_size">1</property>
      <property name="hibernate.c3p0.max_size">100</property>
      <property name="hibernate.c3p0.timeout">300</property>
      <property name="hibernate.c3p0.acquire_increment">1</property>
      <property name="hibernate.c3p0.max_statements">50</property>
      <property name="hibernate.c3p0.maxIdleTime">1</property> 
     
      <!-- Mapping files -->
      <mapping resource="mainpackage/Person.hbm.xml"/>
     <mapping resource="mainpackage/Address.hbm.xml"/>

</session-factory>
</hibernate-configuration>


hibernateRead.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://188.40.85.136/test_replication_db</property>
      <property name="hibernate.connection.username">user</property>
      <property name="hibernate.connection.password">pw</property>
      <!-- property name="hibernate.connection.pool_size">0</property-->
      <property name="show_sql">false</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <!-- property to update database pr create a new one; can be 'create' or 'update' -->
      <property name="hibernate.hbm2ddl.auto">update</property>
     
                 <property name="hibernate.c3p0.min_size">1</property>
      <property name="hibernate.c3p0.max_size">100</property>
      <property name="hibernate.c3p0.timeout">300</property>
      <property name="hibernate.c3p0.acquire_increment">1</property>
      <property name="hibernate.c3p0.max_statements">50</property>
      <property name="hibernate.c3p0.maxIdleTime">1</property>
      
      <!-- Mapping files -->
      <mapping resource="mainpackage/Person.hbm.xml"/>
     <mapping resource="mainpackage/Address.hbm.xml"/>

</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: Re: java.io.EOFException: Can not read response from server
PostPosted: Thu Jan 06, 2011 3:39 pm 
Newbie

Joined: Thu Jan 06, 2011 3:23 pm
Posts: 3
Check out my post on the following thread: viewtopic.php?f=1&t=943079&p=2440195#p2440195


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.