我在获取记录及其零星时遇到错误,它可以通过重新启动服务器或在一段时间后自行修复。我使用的是Struts 2,Oracle 11g,Hibernate 3。
2014-05-06 13:38:51 WARN JDBCExceptionReporter:100 - SQL Error: 17002, SQLState: 08006
2014-05-06 13:38:51 ERROR JDBCExceptionReporter:101 - IO Error: Connection timed out
2014-05-06 13:38:51 ERROR Dispatcher:38 - Exception occurred during processing request: null
java.lang.NullPointerException
at com.tai.dao.UsersTaiImplDAO.listUser(UsersTaiImplDAO.java:37)
at com.tai.web.UsersTaiAction.userLogin(UsersTaiAction.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at
<property name="c3p0.acquire_increment">4</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="c3p0.max_size">20</property>
<property name="c3p0.max_statements">0</property >
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">300</property>
<property name="c3p0.acquireRetryDelay">1000</property>
<property name="c3p0.acquireRetryAttempts">65</property>
<property name="c3p0.breakAfterAcquireFailure">false</property>
<property name="c3p0.numHelperThreads">8</property>
<property name="c3p0.maxAdministrativeTaskTime">1</property>
public List<UsersTai> listUser(String userName, String password) {
_logger.debug("listUser");
List<UsersTai> usersTai = null;
String name= userName.substring(userName.indexOf('@')).trim();
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
usersTai = session.createQuery("from UsersTai where username='" + userName +"' or username= '"+name + "' and USERPASSWORD='"+ password +"'").list();
session.getTransaction().commit();
答案 0 :(得分:1)
如果当前的休眠会话不可用,则无法获得当前的休眠会话。更改代码以打开新会话。
Session session = HibernateUtil.getSessionFactory().openSession();
最后,当您不再需要它时,使用会话工厂关闭会话。