-->
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.  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: could not execute query
PostPosted: Sat Jun 16, 2007 1:25 am 
Newbie

Joined: Fri Jun 15, 2007 11:37 pm
Posts: 11
Hello Frnds,
Im developing one web based program using hibernate . But My problem is when the session is lost , and when I tries to relogin ... the starnge error hits


Hibernate: select users0_.Id as Id0_, users0_.Active as Active0_, users0_.Username as Username0_, users0_.Password as Password0_, users0_.Firstname as Firstname0_, users0_.Lastname as Lastname0_, users0_.Email as Email0_, users0_.Projects_permission as Projects8_0_, users0_.Properties_permission as Properties9_0_, users0_.Clients_permission as Clients10_0_, users0_.Users_permission as Users11_0_, users0_.Resellers_permission as Resellers12_0_, users0_.Accounting_permission as Accounting13_0_ from users users0_ where Username='shabeel' and Password='shabeel'
Error2 : could not execute query


Please verify the program


public class AdminLoginPageAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
AdminLoginPageActionForm formObj = (AdminLoginPageActionForm)form;


/*Get the servlet context */
ServletContext context = request.getSession().getServletContext();
/*Retrieve Session Factory */
SessionFactory _factory = (SessionFactory) context.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);
/*Open Hibernate Session */
Session session = _factory.openSession();
//Criteria Query Example


try {

List result=session.createQuery("from Users where Username='"+formObj.getUsername()+"' and Password='"+formObj.getPassword()+"'").list();
int count=result.size();

HttpSession mysession = request.getSession();


if(mysession.getAttribute("admin_login_status")!=null) {
if(mysession.getAttribute("admin_login_status").equals("true")) {
session.close();
return mapping.findForward("success");
}
}



if(count>0) {

Iterator itr = session.createQuery("from Users where Username='"+formObj.getUsername()+"'").list().iterator();
Users user= (Users) itr.next();
mysession.setAttribute("admin_login_status","true");
mysession.setAttribute("adminloginusername", user.getFirstname()+" "+user.getLastname());
session.close();
return mapping.findForward("success");


} else {
mysession.setAttribute("admin_login_status","false");
mysession.setAttribute("error","invalid");
session.close();
return mapping.findForward("failure");
}
} catch (Exception e) {
System.out.println("Error2 : "+e.getMessage());
session.close();
return mapping.findForward("failure");
}



why this strange error hits? when I restart the server it becomes normal ...

Please help

Regards
/*Close session */



}
}


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sat Jun 16, 2007 7:14 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Will need full stack trace before anything useful can come out.


Top
 Profile  
 
 Post subject: Stack Trace
PostPosted: Sat Jun 16, 2007 2:55 pm 
Newbie

Joined: Fri Jun 15, 2007 11:37 pm
Posts: 11
Hello this is the Exception message and stack trace ...



Hibernate: select users0_.Id as Id0_, users0_.Active as Active0_, users0_.Username as Username0_, users0_.Password as Password0_, users0_.Firstname as Firstname0_, users0_.Lastname as Lastname0_, users0_.Email as Email0_, users0_.Projects_permission as Projects8_0_, users0_.Properties_permission as Properties9_0_, users0_.Clients_permission as Clients10_0_, users0_.Users_permission as Users11_0_, users0_.Resellers_permission as Resellers12_0_, users0_.Accounting_permission as Accounting13_0_ from users users0_ where Username='shabeel' and Password='shabeel'
Error2 : could not execute query
org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:72)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2153)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1127)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at portal.web.AdminLoginPageAction.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:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
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.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.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: Broken pipe

STACKTRACE:

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:2620)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2551)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1512)
at com.mysql.jdbc.ServerPreparedStatement.serverPrepare(ServerPreparedStatement.java:1485)
at com.mysql.jdbc.ServerPreparedStatement.<init>(ServerPreparedStatement.java:151)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1309)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1281)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:442)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:368)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1127)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at portal.web.AdminLoginPageAction.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:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
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.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.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)



Could you please figure it out ? Is it possible ?

Regards
Shabeel


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sat Jun 16, 2007 4:21 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
This problem is related to reinstating the connection. It might be better posted in a mysql forum.

Regards,
Jitendra


Top
 Profile  
 
 Post subject: hmmm
PostPosted: Mon Jun 18, 2007 11:10 am 
Newbie

Joined: Fri Jun 15, 2007 11:37 pm
Posts: 11
Hello,
I increased the connection time out and still the same error after the specified time expires
This is how I did ,,,
mysql> select @@global.wait_timeout;
+-----------------------+
| @@global.wait_timeout |
+-----------------------+
| 28800 |
+-----------------------+

And I have opened and closed all the hibernate session in all action files ...

Regards
Shabeel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 4:01 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
That will not help, the issue here is how do you reconnect to the db after the connection is lost.

Broken pipe tells me that the connection is not getting re-connected.

Regards,
Jitendra


Top
 Profile  
 
 Post subject: Hi
PostPosted: Mon Jun 18, 2007 4:30 pm 
Newbie

Joined: Fri Jun 15, 2007 11:37 pm
Posts: 11
Please refer my first Action (Struts) program where I have opened and closed the hibernate driven session ....

Here is the hibernate plugin which will be initaiated during server startup ....


package portal.net.plugin;

import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.HibernateException;


public class HibernatePlugIn implements PlugIn {
private String _configFilePath = "/hibernate.cfg.xml";

/**
* the key under which the <code>SessionFactory</code> instance is stored
* in the <code>ServletContext</code>.
*/
public static final String SESSION_FACTORY_KEY
= SessionFactory.class.getName();

private SessionFactory _factory = null;

public void destroy() {
try{
_factory.close();
}catch(HibernateException e){
System.out.println("Unable to close Hibernate Session Factory: " + e.getMessage());
}

}

public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
System.out.println("*************************************");
System.out.println("**** Initilizing HibernatePlugIn **********");
Configuration configuration = null;
URL configFileURL = null;
ServletContext context = null;

try{
configFileURL = HibernatePlugIn.class.getResource(_configFilePath);
context = servlet.getServletContext();
configuration = (new Configuration()).configure(configFileURL);
_factory = configuration.buildSessionFactory();
//Set the factory into session
context.setAttribute(SESSION_FACTORY_KEY, _factory);

}catch(HibernateException e){
System.out.println("Error while initializing hibernate: " + e.getMessage());
}
System.out.println("*************************************");

}

/**
* Setter for property configFilePath.
* @param configFilePath New value of property configFilePath.
*/
public void setConfigFilePath(String configFilePath) {
if ((configFilePath == null) || (configFilePath.trim().length() == 0)) {
throw new IllegalArgumentException(
"configFilePath cannot be blank or null.");
}

System.out.println("Setting 'configFilePath' to '" + configFilePath + "'...");
_configFilePath = configFilePath;
}


/*(SessionFactory) servletContext.getAttribute
(HibernatePlugIn.SESSION_FACTORY_KEY);
*/

}


Top
 Profile  
 
 Post subject: hi
PostPosted: Mon Jun 18, 2007 4:33 pm 
Newbie

Joined: Fri Jun 15, 2007 11:37 pm
Posts: 11
And im ready to give my application for your check ? please inform if so ?
That would be a greaaaaaat help....

Regards
Shabeel


Top
 Profile  
 
 Post subject: Re:
PostPosted: Mon Jun 18, 2007 5:25 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Please post your hibernate.cfg.xml also, only the non-mapping section.

I guess the simplest thing here would be to catch this exception and create the session factory again and put it back in the session and use the newly created session factory to openSession and do the processing.

Regards,
Jitendra


Top
 Profile  
 
 Post subject: Conf file
PostPosted: Mon Jun 18, 2007 5:30 pm 
Newbie

Joined: Fri Jun 15, 2007 11:37 pm
Posts: 11
Here is the file


<?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://192.168.1.58/portal_db</property>
<property name="hibernate.connection.username">portal</property>
<property name="hibernate.connection.password">portal</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="/portal/net/dao/hibernate/Users.hbm.xml"/>
<mapping resource="/portal/net/dao/hibernate/Clients.hbm.xml"/>

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 5:42 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Pretty much what I expected. A basic connection mechanism.
Since your database access is spread across various requests it would be a good idea to use a pooled connection instead of a simple connection.

A pooled connection would be a better idea as it would take care of connections in idle state. It is possible that there is some firewall which is causing connection to drop after a few seconds.. as default connection time out is 8 hours 28800 secs :-)

Regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 5:50 pm 
Newbie

Joined: Fri Jun 15, 2007 11:37 pm
Posts: 11
So you are suggesting to use the C3P0 connection pool ?

<!-- configuration pool via c3p0-->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property> <!-- seconds -->
<!-- DEPRECATED very expensive property name="c3p0.validate>-->

If so , how should be the paramaters ?

Thanks
Shabeel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 5:51 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
I have no idea about C3P0 connection pool.. give it a try and see ..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 25, 2007 2:31 pm 
Newbie

Joined: Sun Jun 24, 2007 9:15 pm
Posts: 5
yeah i had similar issue and i use C3P0 connection pool to fix the issue.




shabeel wrote:
So you are suggesting to use the C3P0 connection pool ?

<!-- configuration pool via c3p0-->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property> <!-- seconds -->
<!-- DEPRECATED very expensive property name="c3p0.validate>-->

If so , how should be the paramaters ?

Thanks
Shabeel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 25, 2007 9:31 pm 
Newbie

Joined: Fri Jun 15, 2007 11:37 pm
Posts: 11
Hi ,
I added these lines in hibernate config file , but while startup the server stucked without proceeding. Is there anything else apart from these lines ?


<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property>

Regards
Shabeel


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

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.