웹 응용 프로그램에서 struts2 + hibernate3을 사용하고 있습니다. 정상적으로 작동합니다. 어떤 때는 연결을 열 수 없음을 보여줍니다. 최대 절전 모드 연결에 대한 연결 진술은 동작 클래스입니다.최대 절전 모드에서 너무 많은 연결 오류를 해결하는 방법
protected SessionFactory getSessionFactory() {
try {
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory factory = cfg.buildSessionFactory();
return factory;
} catch (Exception e) {
log.error("sessionFactory", e);
throw new IllegalStateException(
"Could not locate SessionFactory");
}
}
public List viewAllPromotion() {
System.out.println("finding student instance");
try {
Session session = sessionFactory.openSession();
System.out.println("View All Student");
session.beginTransaction();
List results = session.createQuery("from Student").list();
System.out.println("List got Rsults:"+results.size());
session.close();
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
최대 절전 모드 설정 파일 :
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/marksheet</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property name="hibernate.session_factory_name">MySessionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<mapping resource="com/rewardz/model/student.hbm.xml" />
<mapping resource="com/rewardz/model/course.hbm.xml" />
<mapping resource="com/rewardz/model/subject.hbm.xml" />
<mapping resource="com/rewardz/model/staff.hbm.xml" />
<mapping resource="com/rewardz/model/Role.hbm.xml" />
<mapping resource="com/rewardz/model/Privilege.hbm.xml" />
<mapping resource="com/rewardz/model/Logtab.hbm.xml" />
</session-factory>
내가 더 많은 트랜잭션을 수행 할 때 나는 다음과 같은 오류 메시지가 무엇입니까.
HTTP Status 500 - type Exception report
message
descriptionThe server encountered an internal error() that prevented it from fulfilling this request.
exception
org.hibernate.exception.JDBCConnectionException: Cannot open connection
참고 전체 예외의 스택 추적과 그 근본 원인은 글래스 피쉬 서버 오픈 소스 에디션 3.1.1 로그에서 사용할 수 있습니다.
누구든지이 문제를 해결할 수 있도록 도와 줄 수 있습니까? 미리 감사드립니다.
코드에서 변환을 시작했지만 닫지는 않았습니까? –
@ Umesh Awasthi : session.close() 메서드를 사용했습니다. 거래를 어떻게 닫을 수 있는지 알고 싶습니까? – shiva
'tx.commit();과 같은 것 –