Hibernate saveorupdate方法不使用for循环插入多行

时间:2014-10-27 08:39:44

标签: java mysql hibernate

我正在尝试在数据库中插入多行。我在for循环中调用了hibernate saveorupdate方法,用于在表中插入多行。但是下面只插入了一行代码

for(int i=1; i<=noofrows;i++) // value of noofrows is fetched from jsp
  saveintoDB(employeeData);

以下是DAO方法

public EmployeeData saveintoDB(EmployeeData employeeData)  throws Exception{
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();

        session.saveOrUpdate(employeeData);

        tx.commit();
    } finally {
        session.close();
    }
    return employeeData;
}

employeeData对象具有empid作为主键。 hibernate一次只允许插入一行,还是必须在EmployeeData.hbm.xml中对empid属性进行更改?

0 个答案:

没有答案
相关问题