package com.lyq.dao; import com.lyq.persistence.Medicine; import com.lyq.util.HibernateFilter; /** * ҩƷ��ݿ������ * * @author Li Yong Qiang */ public class MedicineDao extends SupperDao { /** * ��ѯҩƷ��Ϣ * * @param id * @return Medicine */ public Medicine loadMedicine(int id) { Medicine med = null; try { session = HibernateFilter.getSession(); // ��ȡSession���� session.beginTransaction(); // �������� // ����ҩƷ��Ϣ med = (Medicine) session.load(Medicine.class, new Integer(id)); session.getTransaction().commit(); // �ύ���� } catch (Exception e) { e.printStackTrace(); // ��ӡ�쳣��Ϣ session.getTransaction().rollback(); // �ع����� } return med; } /** * ͨ��fetchͬʱץȡҩƷ����� * * @param id * @return Medicine */ public Medicine loadMedicineAndCategory(int id) { Medicine med = null; try { session = HibernateFilter.getSession(); // ��ȡSession���� session.beginTransaction(); // �������� // HQL��ѯ��� String hql = "select a from Medicine a join fetch a.category b where a.id = " + id; med = (Medicine) session.createQuery(hql) // ����Query���� .uniqueResult(); // ��ֵ���� session.getTransaction().commit(); // �ύ���� } catch (Exception e) { e.printStackTrace(); // ��ӡ�쳣��Ϣ session.getTransaction().rollback(); // �ع����� } return med; } /** * ���medNo��ѯ * * @param medNo * @return Medicine */ public Medicine findMedicineByMedNo(String medNo) { Medicine med = null; try { session = HibernateFilter.getSession(); // ��ȡSession���� session.beginTransaction(); // �������� // HQL��ѯ��� String hql = "from Medicine d where d.medNo = ?"; med = (Medicine) session.createQuery(hql) // ����Query���� .setParameter(0, medNo) // ��HQL��̬��ֵ .uniqueResult(); // ���ص������� session.getTransaction().commit(); // �ύ���� } catch (Exception e) { e.printStackTrace(); // ��ӡ�쳣��Ϣ session.getTransaction().rollback(); // �ع����� } return med; } }

2860615178 LV4
2024年5月29日
g11865095 LV1
2024年5月14日
javaee165 LV2
2023年2月15日
upup996 LV6
2022年12月15日
微信网友_6261654233190400 LV2
2022年12月14日
Hsy605 LV9
2022年6月22日
北方菜 LV11
2022年5月11日
湫枫1234 LV4
2022年4月3日
wanglinddad LV55
2022年2月23日
破衣飘飘 LV2
2022年2月9日