Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.elearing.impl; import com.elearing.dao.elearningDao; import com.elearing.entity.UserRole; import com.elearing.util.HibernateUtil; import java.io.Serializable; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; /** * * @author Faruqul Islam */ public class UserRoleDaoImpl implements elearningDao<UserRole>, Serializable { @Override public boolean insert(UserRole obj) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); session.save(obj); session.getTransaction().commit(); session.clear(); session.close(); return true; } @Override public boolean update(UserRole obj) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public boolean delete(UserRole obj) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public boolean search(UserRole obj) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public UserRole getObjectById(int id) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public UserRole getObjectByName(UserRole name) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public List<UserRole> getAllObject() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public List<UserRole> getListById(int id) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public List<UserRole> getListByName(UserRole obj) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } public UserRole getRole(String s) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query query = session.createQuery("from UserRole where roleName =:name"); query.setString("name", s); UserRole userRole = (UserRole) query.list().get(0); session.clear(); session.close(); return userRole; } }