📄 threadtypesdaoimpl.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -