⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hibernateutil.java

📁 基于J2EE的办公自动化系统。实现流程定义流程办理等。运用了hibernate+struts+spring框架综合运用的系统。
💻 JAVA
字号:
package com.oa.module.pub.ectomere;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;


public class HibernateUtil {
	
	private SessionFactory sf;
	Session session = null;
	Transaction tx = null;
	public  boolean save(Object object){
		
		try {
			session = sf.openSession();
			tx = session.beginTransaction();
			session.save(object);
			tx.commit();
			session.flush();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			tx.rollback();
		}finally{
			session.close();
			sf.close();
		}
		return false;
	}
	
	public  Object get(Class poclass,Serializable ino){
		Object object = null;
		Session session = null;
		
		try {
			session = sf.openSession();
			object =session.get(poclass,ino);
			session.flush();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			session.close();
			sf.close();
		}
	
		return object;
	}
	
	public boolean update(Object object){
		Session session = null;
		Transaction tx = null;
		try {
			session = sf.openSession();
			tx = session.beginTransaction();
			session.update(object);
			tx.commit();
			session.flush();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			tx.rollback();
		}finally{
			session.close();
			sf.close();
		}
		return false;
	}

	public SessionFactory getSf() {
		return sf;
	}

	public void setSf(SessionFactory sf) {
		this.sf = sf;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -