insert方法
public void insert(Object o){
Session session = HibernateSessionFactorycurrentSession();
Transaction t = sessionbeginTransaction();
sessionsave(o);
mit();
HibernateSessionFactoryclossSession();
}
delete方法
public void delete(Object oSerializable id){
Session session = HibernateSessionFactorycurrentSession():
Transaction t = sessionbeginTransaction();
Object o = sessionget(oclassid);
if(o!=null){
sessiondelete(o);
}
mit();
HibernateSessionFactoryclossSession();
}
update方法
public void update(Object oSerializable id){
Session session = HibernateSessionFactorycurrentSession();
Transaction t = sessionbeginTransaction();
sessionupdate(oid);
mit();
HibernateSessionFactoryclossSession();
}
基于HQL的通用select方法
public ArrayList select(String sql){
Session session = HibernateSessionFactorycurrentSession();
Query query = createQuery(sql);
List list = querylist();
HibernateSessionFactoryclossSession();
return (ArrayList)list;
}
基于SQL的通用select方法
public ArrayList select(String sql) throws Exception{
Session session = HibernateSessionFactorycurrentSession();
Connection con = nnection();
PreparedStatement pstmt = conpreparedStatement(sql);
ResultSet rs = pstmtexecuteQuery();
ResultSetMetaData rsmd = rsgetMetaData();
Hashtable ht = null;
ArrayList array = new ArrayList();
while(rsnext()){
ht = new Hashtable();
for(int i=;i<rsmdgetColumnCount();i++){
htput(rsmdgetColumnName(i+)rsgetObject(i+));
}
arrayadd(ht);
}
HibernateSessionFactoryclossSession();
return array;
}