hibernate - INSERT stmt in HQL -
i new hql, want insert data directly database using insert stmt. when using following code: companymaster model name(companymaster.java)
public void insertcompanydata(companymaster company) { logger.info("entering insertcompanydata"); session session = null; try{ session = getsession(); string hql = "insert companymaster (compname,description,status) select (company.getcompname(),company.getdescription(),company.getstatus())"; //string hql = "insert companymaster company(compname,description,status) values (company.getcompname(),company.getdescription(),company.getstatus())"; query query = session.createquery(hql); //query.setstring("groupid", groupid); query.executeupdate(); } finally{ releasesession(session); } logger.info("exiting insertcompanydata"); }
i getting error this
2013-07-23 09:34:53 info [http-8080-2] companydaoimpl.java:157 - entering insertcompanydata 2013-07-23 09:34:53 error [http-8080-2] errorcounter.java:56 - <ast>:0:0: unexpected end of subtree 2013-07-23 09:34:53 error [http-8080-2] errorcounter.java:56 - <ast>:0:0: unexpected ast node: {vector} 2013-07-23 09:34:53 info [http-8080-2] companymasterserviceimpl.java:121 - entering buildcompanymasterdropdowns .. 2013-07-23 09:34:53 info [http-8080-2] codesdaoimpl.java:27 - entering findcodesbytype() hibernate: select this_.code_master_id code1_8_0_, this_.cr_ts cr2_8_0_, this_.cr_usr cr3_8_0_, this_.md_ts md4_8_0_, this_.md_usr md5_8_0_, this_.code_id code6_8_0_, this_.code_master_type code7_8_0_, this_.code_desc code8_8_0_, this_.status status8_0_ fbms.mst_code this_ this_.code_master_type=? , this_.status=? order this_.code_desc asc 2013-07-23 09:34:53 info [http-8080-2] codesdaoimpl.java:33 - exiting findcodesbytype() ..
please suggest how rectify error...
the select part of query must valid hql select query, returning columns matching ones specified in insert clause.
if want insert new row, values have in memory, table, use persist()
:
companymaster c = new companymaster(); c.setname(somename); ... session.persist(c);
Comments
Post a Comment