Execute HQL statement directly with Hibernate, not manipulate object directly
Example one:
public int ExecuteSQL (String sql, map<string, object> params) {sqlquery sqlquery = getsession (). Createsqlquery (SQL ); if (params!= null) {sqlquery.setproperties (params);//Pass Value} return Sqlquery.executeupdate (); }
Example two:
public void Updateparameter (string Configureid, String configurevalue) {string hql = ' UPDATE ffconfigure SET configureval Ue=:configurevalue WHERE Configureid=:configureid "; SQLQuery sqlquery = GetSession (). Createsqlquery (HQL); map<string,object> map = new hashmap<string,object> (); Map.put ("Configurevalue", Configurevalue); Map.put ("Configureid", Configureid); Sqlquery.setproperties (map); Sqlquery.executeupdate (); }
Example three:
public void Updateparameter (final string configureid, final string configurevalue) throws Exception {Gethibernatetemplat E (). Execute (new Hibernatecallback () {public Object doinhibernate throws hibernateexception {String hql = "UPDATE ffconfigure SET configurevalue=?" WHERE configureid=? "; Query q = session.createquery (HQL); Q.setstring (0, Configureid); Q.setstring (1, configurevalue); Q.executeupdate (); return null; } }); }
Example one, and the example of the beginning is the same, are used sqlquery, very good.
Example three uses a hibernate callback, spring with the transaction situation, update when the background will send SQL statements, but the database is not updated, do not know why.