从表中选择记录并将所选记录插入另一个表时,我的 HQL 插入查询失败。我在控制台中收到所有调试消息“列表内”和迭代列表,但无法在公司表中插入记录。
DAO 类代码:-
public void approveCompany(int companyId, String varifier){
session.beginTransaction();
Query query=session.createQuery("from Provisional where companyID=?");
query.setInteger(0, companyId);
@SuppressWarnings("unchecked")
List<Provisional> list=query.list();
session.getTransaction().commit();
if(list.size()>0)
{
System.out.println("inside list");
for(Provisional p:list){
System.out.println("iterating list");
Query approveQuery=session.createQuery("insert into Company(companyID" +
",annualValueOfTotalExport,annualValueOfTotalSale,cityID,companyAddress" +
"companyEmail,companyName,companyType,contactPersionPosition,contactPersonEmail," +
"contactPersonFaxNo,contactPersonName,contactPersonPhoneNo,countryID,faxNo," +
"licenceNo,loginID,oldPassword,password,phoneNo,stateID,texID,updated_At," +
"verifierID,website,zipCode) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?,?,?)");
approveQuery.setParameter(1, p.getCompanyID());
approveQuery.setParameter(2, p.getAnnualValueOfTotalExport());
approveQuery.setParameter(3, p.getAnnualValueOfTotalSale());
approveQuery.setParameter(4, p.getCityID());
approveQuery.setParameter(5, p.getCompanyAddress());
approveQuery.setParameter(6, p.getCompanyEmail());
approveQuery.setParameter(7, p.getCompanyName());
approveQuery.setParameter(8, p.getCompanyType());
approveQuery.setParameter(9, p.getContactPersonPosition());
approveQuery.setParameter(10, p.getContactPersonEmail());
approveQuery.setParameter(11, p.getContactPersonFaxNo());
approveQuery.setParameter(12, p.getContactPersonName());
approveQuery.setParameter(13, p.getContactPersonPhoneNo());
approveQuery.setParameter(14, p.getCountryID());
approveQuery.setParameter(15, p.getFaxNo());
approveQuery.setParameter(16, p.getLicenceNo());
approveQuery.setParameter(17, p.getLoginID());
approveQuery.setParameter(18, p.getPassword());
approveQuery.setParameter(19, p.getPassword());
approveQuery.setParameter(20, p.getPhoneNo());
approveQuery.setParameter(21, p.getStateID());
approveQuery.setParameter(22, p.getTaxID());
approveQuery.setParameter(23, p.getCreated_On());
approveQuery.setParameter(24, varifier);
approveQuery.setParameter(25, p.getWebsite());
approveQuery.setParameter(26,p.getZipCode());
approveQuery.executeUpdate();
session.getTransaction.commit();
}
}
session.close();
}