java - How to retrieve,update,delete data from database using DAO method in Hibernate -
how retrieve,update,delete data database using dao method in hibernate.
my dao this:
package com.sample.common.impl; import java.util.list; import com.sample.common.employee; public interface employeedao { public list<employee> getallemployee(); public void updateemployee(employee emp); public void deleteemployee(employee emp); }
my implementation class this:
package com.sample.common.impl; import java.util.arraylist; import java.util.list; import org.hibernate.sessionfactory; import com.sample.common.employee; public class employeedaoimpl implements employeedao { private sessionfactory sessionfactory; public list<employee> getallemployee() { return null; } public void updateemployee(employee emp) { } public void deleteemployee(employee emp) { } }
how create query select,update , delete. can please suggest possible solution
you have update code below
public void deleteemployee(employee emp) { session session = sessionfactory.getcurrentsession(); session.delete(emp); logger.debug(emp.getclass()); } public void updateemployee(employee emp) { session session = sessionfactory.getcurrentsession(); session.update(emp); logger.debug(emp.getclass()); } public list<employee> getallemployee(){ string query ="select e employee e"; list<employee> emplist = session.createquery(query); return emplist; }
hope stuff works.
Comments
Post a Comment