2 Replies Latest reply on Sep 5, 2006 12:10 AM by dennis zane

    a unidirectonal one-to many example,anyone can help me?

    dennis zane Newbie

      I wrote a example following the <mastringEJB4th>.

      1.First,a company.java file:
      @Entity
      public class Company implements Serializable {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;

      private String name;

      private Set employees;

      public Company() {
      }

      @OneToMany(cascade = CascadeType.PERSIST, fetch=FetchType.EAGER,mappedBy="company")
      public Set getEmployees() {
      return employees;
      }

      public void setEmployees(Set employees) {
      this.employees = employees;
      }

      public Integer getId() {
      return id;
      }

      public void setId(Integer id) {
      this.id = id;
      }

      public String getName() {
      return name;
      }

      public void setName(String name) {
      this.name = name;
      }

      }


      2.And then ,Employee.java:
      @Entity()
      public class Employee implements Serializable {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;

      private String name;

      private char sex;

      public Employee() {
      }

      public Integer getId() {
      return id;
      }

      public void setId(Integer id) {
      this.id = id;
      }

      public String getName() {
      return name;
      }

      public void setName(String name) {
      this.name = name;
      }

      public char getSex() {
      return sex;
      }

      public void setSex(char sex) {
      this.sex = sex;
      }

      }


      3.I wrote a SLSB to test the example:
      ......
      Company company = new Company();
      Set employees = new HashSet();
      Employee employee = new Employee();
      employee.setName("jordan");
      employee.setSex('M');
      employees.add(employee);
      employee = new Employee();
      employee.setName("dennis");
      employee.setSex('M');
      employees.add(employee);
      employee = new Employee();
      employee.setName("catty");
      employee.setSex('F');
      employees.add(employee);
      employee = new Employee();
      employee.setName("inter");
      employee.setSex('F');
      employees.add(employee);
      employee = new Employee();
      employee.setName("James Gosling");
      employee.setSex('M');
      employees.add(employee);
      company.setEmployees(employees);
      em.persist(company);
      }

      public List getCompanies() {
      Query query = em.createQuery("SELECT c FROM Company c");
      return query.getResultList();
      }
      ..........
      but when I tried to deploy the example to the JBoss Server,it goes wrong:
      Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(employees)]

      I don't know why!!!Is my code have any problems?anyone can help me?thanks.