0
我是Hibernate的新手,開發一個從URL獲取參數的servlet,創建一個Hibernate對象,然後將其存儲到MySQL數據庫中。同時向MySQL添加Hibernate對象
我正在同時發送1000個URL。當我查看MySQL表時,它只將最後一個對象添加到數據庫中。
doGet方法:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//HttpSession session = request.getSession(true);
//session.putValue("uid", count);
String id = request.getParameter("id");
String url = request.getParameter("url");
String lastVisitTime = request.getParameter("lastVisitTime");
String visitCount = request.getParameter("visitCount");
String title = request.getParameter("title");
String typedCount = request.getParameter("typedCount");
HistoryItem hi = new HistoryItem(id, url, lastVisitTime, visitCount, title, typedCount);
File f = new File("C:\\Users\\atılay\\Desktop\\apache-tomcat-7.0.30-windows-x64\\jspservlets\\UserModeling\\src\\hibernate.cfg.xml");
SessionFactory sessionFactory = new Configuration().configure(f).buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(hi);
session.getTransaction().commit();
session.flush();
session.close();
}
HistoryItem:
public class HistoryItem {
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
@Basic(optional = false)
private int i;
private String id = "";
private String url = "";
private String lastVisitTime = "";
private String visitCount = "";
private String title = "";
private String typedCount = "";
}
問題是什麼?我找不到任何解決方案。