/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dao;
import bo.MetCernerii;
import bo.HibernateUtil;
import daoI.IMetCerneriiDao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
public class MetCerneriiDao implements IMetCerneriiDao {
Session session = null;
public MetCernerii getMetCerneriiByID(int metCID) {
MetCernerii metC = null;
List<MetCernerii> metCList = null;
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from MetCernerii as lang where lang.idCernere='" + metCID + "'");
metCList = (List<MetCernerii>) q.list();
metC = ((MetCernerii) metCList.get(0));
//tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
return metC;
}
public MetCernerii getMetCerneriiByIDProba(int probaID) {
MetCernerii metC = null;
List<MetCernerii> metCList = null;
try {
this.session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from MetCernerii as lang where lang.proba.idProba='" + probaID + "'");
metCList = (List<MetCernerii>) q.list();
metC = ((MetCernerii) metCList.get(0));
//tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
return metC;
}
public void saveOrUpdate(MetCernerii metC) {
try {
session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
if (metC.getIdCernere() == null) {
session.save(metC);
} else {
session.merge(metC);
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}