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