HibernateUtil.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:1k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.system;
- import java.io.Serializable;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import com.oa.module.pub.ectomere.HibernateSessionFactory;
- public class HibernateUtil {
- public static boolean save(Object object){
- Session session = null;
- Transaction tx = null;
- try {
- session = HibernateSessionFactory.currentSession();
- tx = session.beginTransaction();
- session.save(object);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- HibernateSessionFactory.closeSession();
- }
- return false;
- }
- public static Object get(Class poclass,Serializable ino){
- Object object = null;
- Session session = null;
- try {
- session = HibernateSessionFactory.currentSession();
- object =session.get(poclass,ino);
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- HibernateSessionFactory.closeSession();
- }
- return object;
- }
- public static boolean update(Object object){
- Session session = null;
- Transaction tx = null;
- try {
- session = HibernateSessionFactory.currentSession();
- tx = session.beginTransaction();
- session.update(object);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- HibernateSessionFactory.closeSession();
- }
- return false;
- }
- }