我是 Hibernate 新手,正在开发一个从 URL 获取参数的 servlet,创建一个 Hibernate 对象,然后将其存储到 MySQL 数据库中。
我同时发送 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();
}
历史项目:
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 = "";
}
问题是什么?我找不到任何解决方案。