1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Transaction;
public class changer {
public static void change(Integer annee,String mois,String typ,Integer bdg){
Criteria crit = HibernateSessionFactory.getSession().createCriteria(Capexetd.class)
.add( Restrictions.eq("annee", annee) )
.add( Restrictions.eq("mois", mois) )
.add( Restrictions.eq("type", typ)
);
Capexetd res = (Capexetd ) crit.uniqueResult();
if (res!=null) {
Session session =HibernateSessionFactory.getSession();
Transaction tx=session.beginTransaction();
res.setBudget(bdg);
tx.commit();
}
else{
Session session =HibernateSessionFactory.getSession();
Capexetd c=new Capexetd();
c.setId(12);
c.setAnnee(annee);
c.setBudget(bdg);
c.setMois(mois);
c.setType(typ);
session.save(c);
}
}
} |
Partager