Webアプリケーションでstruts2 + hibernate3を使用しています。正常に動作しています。接続を開くことができない場合があります。休止状態に接続するためのFollwoing接続ステートメントアクションクラス。Hibernateで多すぎる接続エラーを解決する方法
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;
}
}
Hibernate設定ファイル:
<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
ノートの完全な例外のスタックトレースとその根本原因は、GlassFishアプリケーションサーバー3.1.1ログでご利用いただけます。
誰でもこの問題を解決するのに役立つことができますか?前もって感謝します。
コードでコード変換を開始しましたが、 –
@ Umesh Awasthi:私はsession.close()メソッドを使用しました。トランザクションを終了する方法を知ってもいいですか? – shiva
「tx.commit();」のようなもの –