Unknown mappedBy in referenced property unknown

namrata
2014-04-24
2014-04-29
  • namrata
    namrata
    2014-04-24

    hi,
    PLease help me with the following code.

    Department.java

    import java.io.*;

    import javax.persistence.*;

    import org.openxava.annotations.*;

    @Entity

    @Table(name="Dept_Master")
    public class Department implements Serializable
    {
    private String deptCode;
    private String deptName;
    private Employee empl;

    public Department(String deptCode, String deptName, 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;
    }
    
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_code")
    public Employee getEmpl() {
        return this.empl;
    }
    
    public void setEmpl(Employee empl) {
        this.empl = empl;
    }
    

    }

    Employee.java

    import java.io.;
    import java.util.
    ;

    import javax.persistence.*;

    @Entity

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

    /
    private static final long serialVersionUID = 1L;

    private String empCode;
    
    private String empName;
    
    private String deptCode;
    
    private String empDob;
    
    private String empDoj;
    
    private Collection<Department> department;
    
    public Employee(String empCode, String empName, String deptCode,
            String empDob, String empDoj, Collection<Department> department)
    {
    
        this.empCode = empCode;
        this.empName = empName;
        this.deptCode = deptCode;
        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=10)
    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;
    }
    
    @OneToOne(fetch = FetchType.LAZY, mappedBy = "empl")
    public Collection<Department> getDepartment() {
        return this.department;
    }
    
    public void setDepartment(Collection<Department> department) {
        this.department = department;
    }
    

    }

    I keep getting errors as follows:

    [hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
    [hibernatetool] To get the full stack trace run ant with -verbose
    [hibernatetool] Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?
    [hibernatetool] java.lang.reflect.InvocationTargetException
    [hibernatetool] javax.persistence.PersistenceException: [PersistenceUnit: junit] Unable to configure EntityManagerFactory
    [hibernatetool] org.hibernate.AnnotationException: Unknown mappedBy in: org.openxava.payroll.module.Employee.department, referenced property unknown: java.util.Collection.empl

    BUILD FAILED
    /usr/openxava/workspace/Test/build.xml:46: The following error occurred while executing this line:
    /usr/openxava/workspace/Test/build.xml:1022: Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?

     
  • Javier Paniza
    Javier Paniza
    2014-04-29

    Hi Namrata,

    try to change in Deparment this:

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_code")
    public Employee getEmpl() {
    

    by this:

    @ManyToOne
    @JoinColumn(name = "dept_code")
    public Employee getEmpl() {
    

    If Employee has one-to-many relationship with Deparment, Deparment must have a many-to-one with Employee.


    Help others in this forum as I help you.