Issue in displaying data from two tables

namrata
2014-04-25
2014-04-29
  • namrata

    namrata - 2014-04-25

    hi,
    I am working towards displaying data from two tables
    1.Emp_Master->Emp_Code,Emp_Name,Dept_Code,Emp_Dob,Emp_Doj
    2.Dept_Master->Dept_Code,Dept_Name

    I am using MySQL.

    I want to display data as follows.

    Emp_Code(from emp_master table)||Emp_Name(from emp_master table)||Dept_Name(from dept_master table)|Emp_Dob(from emp_master table)

    Following are the entity classes:

    Employee

    @Entity
    @View(members="empCode;"+
    "empName;"+
    "department;"+
    "deptName{dept_name};"+
    "empDob;"+
    "empDoj;")

    @Table(name="Emp_Master")
    public class Employee implements Serializable
    {

    private static final long serialVersionUID = 1L;
    
    private String empCode; 
    private String empName;
    private String deptName;
    private String empDob;
    private String empDoj;
    private Department department;
    
    public Employee()
    {
    
    }
    public Employee(String empCode, String empName, String deptName,String empDob, String empDoj, Department department)
    {
    
        this.empCode = empCode;
        this.empName = empName;
        this.deptName= deptName;
        this.empDob=empDob;
        this.empDoj = empDoj;
        this.department = department;
    }
    

    //------------------------------------------------------
    @Id
    @Column(name="emp_code",length=10)
    public String getEmpCode() {
    return this.empCode;
    }
    //------------------------------------------------------

    public void setEmpCode(String empCode) {
        this.empCode = empCode;
    }
    

    //------------------------------------------------------
    @Column(name="emp_name",length=30)
    public String getEmpName() {
    return this.empName;
    }
    //------------------------------------------------------

    public void setEmpName(String empName) {
        this.empName = empName;
    }
    
    /*@Column(name="dept_code",length=30)
    public String getDeptCode() {
        return this.deptCode;
    }
    
    public void setDeptCode(String deptCode) {
        this.deptCode = deptCode;
    }*/
    

    //------------------------------------------------------
    @Column(name="emp_dob",length=9)
    public String getEmpDob()
    {
    return this.empDob;
    }

    //------------------------------------------------------

    public void setEmpDob(String empDob) {
        this.empDob = empDob;
    }
    

    //------------------------------------------------------
    @Column(name="emp_doj",length=9)
    public String getEmpDoj()
    {
    return this.empDoj;
    }
    //------------------------------------------------------

    public void setEmpDoj(String empDoj) 
    {
        this.empDoj = empDoj;
    }
    
    @ManyToOne(fetch = FetchType.LAZY)
    //@JoinColumn(name = "dept_code")
    @JoinTable(name="Emp_Master",joinColumns = {@JoinColumn(name = "deptCode")})
    @DescriptionsList(descriptionProperties="deptName",depends="department",condition="${deptCode}=?")
    
    public Department getDepartment() {
        return this.department;
    }
    
    public void setDepartment(Department department) {
        this.department = department;
    }
    
    @Column(name="dept_name",length=20)
    public String getdeptName() {
        return this.department.getDeptName();
    }
    public void setdeptName(String deptName) {
        this.deptName = deptName;
    }
    

    }

    Department

    @Entity

    @Table(name="Dept_Master")
    public class Department implements Serializable
    {

    private static final long serialVersionUID = 1L;
    
    private String deptCode;
    private String deptName;
    private Collection<Employee> empl;
    
    public Department()
    {
    
    }
    public Department(String deptCode, String deptName, Collection<Employee> empl)
    {
        this.deptCode = deptCode;
        this.deptName = deptName;
        this.empl=empl;
    }
    
    @Id
    @Column(name="dept_code",length=10)
    public String getDeptCode() {
        return this.deptCode;
    }
    
    public void setDeptCode(String deptCode) {
        this.deptCode = deptCode;
    }
    
    @Column(name="dept_name",length=20)
    public String getDeptName() {
        return this.deptName;
    }
    
    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }
    
    @OneToMany(fetch = FetchType.LAZY,mappedBy="department")
    public Collection<Employee> getEmpl() {
        return this.empl;
    }
    
    public void setEmpl(Collection<Employee> empl) {
        this.empl = empl;
    }
    

    }

    Data for empcode,empname,dob,is getting displayed but not for deptname.
    Firstly I want to know if the approach is right?
    Or is there any other way i could do this.

    Please help!!

    }

     
  • namrata

    namrata - 2014-04-25

    Output:

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks