[jboss-user] [EJB 3.0] - a unidirectonal one-to many example, anyone can help me?

killme2008 do-not-reply at jboss.com
Sun Sep 3 09:52:41 EDT 2006


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.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969097#3969097

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969097



More information about the jboss-user mailing list