Hibernate を使用して非常に単純なデータベースを作成しますが、「接続が多すぎます」という Glassdoor サーバー エラーが頻繁に発生することに注意してください。
これは、データベース項目を更新/追加/削除するときに接続を正しく閉じていないためだと思います。
updateEntry.jsp で私が行っていることの例を次に示します。あからさまな問題はありますか? そうでない場合は、removeEntry.jsp と newEntry.jsp を投稿できます。
<%@page import="java.util.Date" %>
<%@page import="org.hibernate.Session" %>
<%@page import="org.hibernate.SessionFactory" %>
<%@page import="org.hibernate.Transaction" %>
<%@page import="org.hibernate.cfg.Configuration" %>
<%@page import="java.util.Date" %>
<%
String nId = request.getParameter("pID");
String naddress = request.getParameter("pAddress");
String nstatus = request.getParameter("pStatus");
String nassigned = request.getParameter("pAssigned");
String nnote = request.getParameter("pNote");
if (!naddress.equals("undefined"))
{
// This step will read hibernate.cfg.xml and prepare hibernate for use
org.hibernate.SessionFactory sessionFactory1 = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
org.hibernate.Session session1 = sessionFactory1.openSession();
org.hibernate.Query query1 = session1.createQuery("update Leads set Address = :naddr where Id = :nid");
query1.setParameter("nid", nId);
query1.setParameter("naddr", naddress);
query1.executeUpdate();
//out.println("Update successfully with: " + naddress);
// Actual contact insertion will happen at this step
session1.flush();
session1.close();
}
if (!nstatus.equals("undefined"))
{
// This step will read hibernate.cfg.xml and prepare hibernate for use
org.hibernate.SessionFactory sessionFactory2 = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
org.hibernate.Session session2 = sessionFactory2.openSession();
org.hibernate.Query query2 = session2.createQuery("update Leads set Status = :nstatus where Id = :nid");
query2.setParameter("nid", nId);
query2.setParameter("nstatus", nstatus);
query2.executeUpdate();
//out.println("Update successfully with: " + nstatus);
// Actual contact insertion will happen at this step
session2.flush();
session2.close();
}
if (!nassigned.equals("undefined"))
{
// This step will read hibernate.cfg.xml and prepare hibernate for use
org.hibernate.SessionFactory sessionFactory3 = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
org.hibernate.Session session3 = sessionFactory3.openSession();
org.hibernate.Query query3 = session3.createQuery("update Leads set Assigned = :nassigned where Id = :nid");
query3.setParameter("nid", nId);
query3.setParameter("nassigned", nassigned);
query3.executeUpdate();
//out.println("Update successfully with: " + nassigned);
// Actual contact insertion will happen at this step
session3.flush();
session3.close();
}
if (!nnote.equals("undefined"))
{
// This step will read hibernate.cfg.xml and prepare hibernate for use
org.hibernate.SessionFactory sessionFactory4 = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
org.hibernate.Session session4 = sessionFactory4.openSession();
org.hibernate.Query query4 = session4.createQuery("update Leads set Notes = :nnote where Id = :nid");
query4.setParameter("nid", nId);
query4.setParameter("nnote", nnote);
query4.executeUpdate();
//out.println("Update successfully with: " + nnote);
// Actual contact insertion will happen at this step
session4.flush();
session4.close();
}
%>