hibernate通用方法
来源:互联网 发布:自己的淘宝等级怎么看 编辑:程序博客网 时间:2024/05/22 10:49
hibernate通用方法
1.insert方法
public void insert(Object o)
2.delete方法
public void delete(Object o,Serializable id)
3.update方法
public void update(Object o,Serializable id)
4.基于HQL的通用select方法
public ArrayList select(String sql)
5.基于SQL的通用select方法
public ArrayList select(String sql) throws Exception
详细代码如下:
insert方法
public void insert(Object o){
Session session = HibernateSessionFactory.currentSession();
Transaction t = session.beginTransaction();
session.save(o);
t.commit();
HibernateSessionFactory.clossSession();
}
delete方法
public void delete(Object o,Serializable id){
Session session = HibernateSessionFactory.currentSession():
Transaction t = session.beginTransaction();
Object o = session.get(o.class,id);
if(o!=null){
session.delete(o);
}
t.commit();
HibernateSessionFactory.clossSession();
}
update方法
public void update(Object o,Serializable id){
Session session = HibernateSessionFactory.currentSession();
Transaction t = session.beginTransaction();
session.update(o,id);
t.commit();
HibernateSessionFactory.clossSession();
}
基于HQL的通用select方法
public ArrayList select(String sql){
Session session = HibernateSessionFactory.currentSession();
Query query = createQuery(sql);
List list = query.list();
HibernateSessionFactory.clossSession();
return (ArrayList)list;
}
基于SQL的通用select方法
public ArrayList select(String sql) throws Exception{
Session session = HibernateSessionFactory.currentSession();
Connection con = session.connection();
PreparedStatement pstmt = con.preparedStatement(sql);
ResultSet rs = pstmt.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
Hashtable ht = null;
ArrayList array = new ArrayList();
while(rs.next()){
ht = new Hashtable();
for(int i=0;i<rsmd.getColumnCount();i++){
ht.put(rsmd.getColumnName(i+1),rs.getObject(i+1));
}
array.add(ht);
}
HibernateSessionFactory.clossSession();
return array;
}
- hibernate通用方法
- hibernate通用方法
- hibernate通用方法
- hibernate的延迟加载通用方法
- struts+spring+hibernate通用分页方法
- struts+spring+hibernate通用分页方法
- Hibernate 通用的添加实体方法
- hibernate---HQL、通用方法的抽取实现
- hibernate与spring整合后通用分页查询方法
- hibernate学习笔记4---HQL、通用方法的抽取实现
- 泛型+hibernate封装任意数据库数据的通用方法
- 通用方法
- hibernate数据库连接通用
- hibernate通用分页类
- Hibernate的通用dao
- Hibernate 通用 baseDao
- 通用Hibernate-Dao
- Hibernate通用分页
- delete的误解
- Udev 基本工作原理
- c语言常见错误分析
- wmware虚拟机搭建oracle 集群RAC环境
- html
- hibernate通用方法
- MFC界面开发笔记
- Linux服务cannot change directory错误解决方法
- Ubuntu9.10下编译Android源码
- ORA-02291:parent key not found
- POJ3712Edges and More Edges
- android.webkit.WebView 使用 SINGLE_COLUMN layout algorithm 导致程序意外退出的解决办法
- 設計カバレッジで漏れの確認
- python 俄罗斯方块