【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“MaritalUtil.java”一文,供大家参考学习!
/*
* MaritalUtil.java
*
* Created on 2006年6月10日, 下午5:56
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package model.hr.hibernate;
import dbservice.hibernate.HibernateService;
import java.util.*;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
*
* @author Administrator
*/
public class MaritalUtil {
public static boolean insert(Marital marital) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
session.save(marital);
transaction.commit();
b = true;
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
b = false;
}
catch (Exception e) {
e.printStackTrace();
b = false;
}
finally {
HibernateService.closeSession(session);
return b;
}
}
public static List findAll() {
List list = null;
list = HibernateService.execQuery("from Marital");
return list;
}
public static boolean addEmployees(String id, Employee employee) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Marital marital = new Marital();
session.load(marital, Byte.valueOf(id));
employee.setMarital(marital);
session.update(marital);
transaction.commit();
b = true;
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
b = false;
}
catch (Exception e) {
e.printStackTrace();
b = false;
}
finally {
HibernateService.closeSession(session);
return b;
}
}
}