Hibernate之使用insert into语句

public void insertIntoCMS(Agent agent) {
Session session = this.getSession();
session.save(agent);
ConfigInfo configInfo = new ConfigInfo();
String roleid = configInfo.getPropertiesValue("parameter","roleId");
insertIntoAgentRole(agent.getAgentId(),roleid);
}
public void insertIntoAgentRole(final String agentId, final String  roleId) {
getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session){
String sql = "insert into p_agentrole (agentid,roleid)  values(?,?)";
Query query= session.createSQLQuery(sql);
query.setString(0, agentId);
query.setString(1, roleId);
query.executeUpdate();
return null;
}
});
}

你可能感兴趣的:(【SSH】)