spring mvc - View layer of child still showing previous value of parent table column departmentID ,but parent is deleted -


i stuck on problem have made normal project using spring mvc , spring-data in have dao layer,service layer ,controller , view layer. in project have department, employee,employeeproject table. when delete department corresponding employee table column departmentid set null.so reflected in database when in delete department ui ,but when again see employee through getallemployee button @ time previous value of department still showing in ui instead of value null in database. when restart server value not showing why ?

this function getallemployee() in 3 layer

in dao layer

   /**      * employee detail database      *       * @return list of employees      */     @override     public list<employee> getallemployees() {         list<employee> employeelist = employeerepository.findall(new sort(                 direction.asc, "employeenumber"));          return employeelist;     } 

in service layer

    @override     public list<employeebo> getallemployees() {         list<employeebo> employeebolist = null;         list<employee> employeelist = employeedao.getallemployees();         if (employeelist != null && employeelist.size() != 0) {             employeebolist = new arraylist<employeebo>();             (employee employee : employeelist) {                 employeebolist.add(convertemployeeentitytobo(employee));             }         }       return employeebolist; 

and in controller

@requestmapping(value = "/getallemployee", method = requestmethod.get) public modelandview getallemployee(         @modelattribute("employeebo") employeebo employeebo) {     modelandview modelandview = new modelandview();     list<employeebo> list = employeeservice.getallemployees();     modelandview.addobject("employeebo", employeebo);     modelandview.addobject("listemployeebo", list);     modelandview.setviewname("employeelist");     return modelandview; } 

department class pozo

    @entity @table(name = "department") public class department extends baseobject {      private static final long serialversionuid = 1l;     @id     @column(name = "department_id")     private string departmentid;     @column(name = "department_name")     private string departmentname;     @column(name = "department_location")     private string departmentlocation;     @onetomany     @joincolumn(name = "department_id", insertable = false, updatable = false)     collection<employee> employeelist = new arraylist<employee>(); 

employee pozo class

    @entity @table(name = "employee") public class employee extends baseobject {      private static final long serialversionuid = 1l;     @id     @column(name = "employee_number")     private long employeenumber;     @column(name = "first_name")     private string firstname;     private string title;     @column(name = "department_id")     private string departmentid;     @column(name = "mobile_number")     private long mobilenumber;     @column(name = "date_of_birth")     @temporal(temporaltype.date)     private date dateofbirth;      @onetomany(mappedby = "employee", cascade = cascadetype.all, orphanremoval = true)     collection<employeeproject> employeeprojectlist = new arraylist<employeeproject>(); 

these 2 class dept , employee pozo classes have setter getter

repository interface of department

    import java.util.list;  import org.springframework.data.jpa.repository.jparepository; import org.springframework.data.jpa.repository.modifying; import org.springframework.data.jpa.repository.query; import org.springframework.data.repository.query.param;  import com.nousinfo.tutorial.model.department;  /**  * repository interface {@link department} instances. provides basic crud  * operations due extension of {@link jparepository}. includes custom  * implemented functionality extending {@link jparepository}.  *   * @author ankurj  */ public interface departmentrepository extends jparepository<department, string> {     /**      * find department given department name. method      * translated query constructing directly method name      * there no other query declared.      *       * @param name      *            departmentname find      * @return list of departments      */     public list<department> findbydepartmentnamelike(string name);      /**      *       * update employee given departmentid. method      * translated query using 1 declared in {@link query}      * annotation declared one.      *       * @param departmentid      *            departmentid set      * @param deptid      *            departmentid deleted      * @return integer value      */     @modifying     @query("update employee set department_id = :departmentid department_id = :deptid")     public int updateemployeedepartmentid(             @param("departmentid") string departmentid,             @param("deptid") string deptid); } 


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -