threadtypesdaoimpl.java
来自「论坛软件系统亦称电子公告板(BBS)系统」· Java 代码 · 共 65 行
JAVA
65 行
package cn.jsprun.dao.posts;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.jsprun.domain.Threadtypes;
import cn.jsprun.utils.HibernateUtil;
public class ThreadTypesDaoImpl implements ThreadTypesDao {
public List<Threadtypes> getAllThreadtypes() {
List<Threadtypes> allThreadtypes = null;
Transaction tr = null;
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
tr = session.beginTransaction();
Query query = session.createQuery("from Threadtypes t");
allThreadtypes = query.list();
tr.commit();
} catch (HibernateException he) {
if(tr!=null){
tr.rollback();
}
he.printStackTrace();
}
return allThreadtypes;
}
public Threadtypes getThreadtypesbyId(short typeid) {
Transaction tr = null;
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
tr = session.beginTransaction();
Threadtypes threadtype = (Threadtypes)session.get(Threadtypes.class, typeid);
tr.commit();
return threadtype;
} catch (HibernateException he) {
if(tr!=null){
tr.rollback();
}
he.printStackTrace();
}
return null;
}
public List<Threadtypes> findThreadtypeByHql(String hql) {
Transaction tr = null;
try{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
tr = session.beginTransaction();
Query query = session.createQuery(hql);
List<Threadtypes> list = query.list();
tr.commit();
return list;
}catch(HibernateException he){
if(tr!=null){
tr.rollback();
}
he.printStackTrace();
}
return null;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?