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.  [ 1 post ] 
Author Message
 Post subject: Broken pipe with Hibernate and Struts
PostPosted: Fri Jun 12, 2009 1:40 am 
Newbie

Joined: Fri Jun 12, 2009 12:51 am
Posts: 1
Hi All,
I am working on a smaall erp, previously this is struts+simple jdbc connections, now we are using hibernate and jdbc connection both,
we are facing following exception,
Caused by: java.net.SocketException: Broken pipe
so this is what I have,

in a common_config.xml
Code:
<data-sources>
        <data-source type="org.apache.tomcat.dbcp.dbcp.BasicDataSource" >
            <set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
            <set-property property="url" value="jdbc:mysql://xxx:xxx/abc?autoReconnect=true" />
            <set-property property="username" value="abc" />
            <set-property property="password" value="abc" />
            <set-property property="maxActive" value="1000" />
            <set-property property="maxWait" value="3" />
            <set-property property="defaultAutoCommit" value="false" />
            <set-property property="defaultReadOnly" value="false" />
        </data-source>
</data-sources>


my cfg has,
Code:
<hibernate-configuration>
    <session-factory>
          <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
          <property name="hibernate.connection.url">jdbc:mysql://xxx:xxx/abc</property>
          <property name="hibernate.connection.username">abc</property>
          <property name="hibernate.connection.password">abc</property>
          <property name="hibernate.connection.pool_size">300</property>
          <property name="show_sql">true</property>
          <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
          <property name="hibernate.hbm2ddl.auto">update</property>
          <!-- Mapping files -->
    </session-factory>
</hibernate-configuration>


This is my DataConnection from where I am getting session(in case of hibernate) and connection(in case of normal sql queries) objects:
Code:
public class DataConnection {
    Session session = null;
    Connection con = null;
    private static final SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    public Session getSession() {
        if(session != null){
            session = sessionFactory.getCurrentSession();
        }else{
            session = sessionFactory.openSession();           
        }
        return session;
    }
    public void closeSession() {
        try {
            con.close();
            if (session != null) {
                session.close();
            }
        } catch (Exception ex) {
            Logger.getLogger(DataConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public Connection getDataSourceConnection(DataSource dataSource) {
        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;
    }
}


And in my DAO I am using load(),
Quote:
obj = (QuizStudent) session.load(QuizStudent.class, testRegId);

and when I am using normal sql queries m using,
Code:
con = new DataConnection().getDataSourceConnection(dataSource);
st = con.createStatement();
rs = st.executeQuery(SQL_QUERY);


This code is running fine in continuation....
but we are facing following problem when the system didnt get any request for say 8-10 hrs or a day.

Code:
13:58:22,017 INFO  [STDOUT] 13:58:22,017 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: 08003
13:58:22,017 INFO  [STDOUT] 13:58:22,017 ERROR [JDBCExceptionReporter] No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:


** BEGIN NESTED EXCEPTION **

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
MESSAGE: Communications link failure

Last packet sent to the server was 0 ms ago.

STACKTRACE:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
        at sun.reflect.GeneratedConstructorAccessor80.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3136)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1834)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1976)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1888)
        at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:85)
        at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
        at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:529)
        at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:521)
        at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:517)
        at org.gtt.erp.college.dao.CollegeRegistrationDao.setCollegeRegistrationInfo(Unknown Source)
        at org.gtt.erp.college.action.CollSpecializationRegistrationAction.execute(Unknown Source)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
        at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
        at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:754)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:684)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:876)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3121)
        ... 43 more




One important thing as I said after some idel time I am facing above exception while submitting a student registration form, but if I go back and again submit the form, my information is getting inserted into the database and everything is running fine ...




Plz help me to resolve this issue...

Thanks in advance.


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.