• Post Reply Bookmark Topic Watch Topic
  • New Topic

Define OneToMany table column as part of composite key (primary-key class) query  RSS feed

Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am wondering whether it is possible to define a OneToMany column field as part of a composite key (primary-key class) such as the following:

public class Employee implements Serializable {

@GeneratedValue(strategy = GenerationType.IDENTITY)

private int number;
public int getNumber() { return number; }
public void setNumber(int number) { this.number = number; }

private String surname;
public String getSurname() { return surname; }
public void setSurname(String surname) { this.surname = surname; }

@OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
private Collection<Skillset> skillsets = new ArrayList<Skillset>();
public Collection<Skillset> getSkillsets() { return skillsets; }

public void setSkillsets(Collection<Skillset> skillsets) { this.skillsets = skillsets; }


public class EmployeePK implements java.io.Serializable
private int employee_number;
private String surname;
private String skillset;

public EmployeePK() {}

public EmployeePK(int employee_number, String surname, String skillset)
this.employee_number = employee_number;
this.skillset = skillset;
this.surname = surname;

public int getEmployee_number() { return this.employee_number; }

public void setEmployee (int employee_number) { this.employee_number = employee_number; }

public String getSkillset() { return this.skillset; }

public void setSkillset(String skillset) { this.skillset = skillset; }

public String getSurname() { return this.surname; }

public void setSurname(String surname) { this.surname = surname; }

public boolean equals(Object obj) { ... }

public int hashcode() { .... }
There are plenty of material on setting up composite key (primary-key class) but most of them uses basic data types.

I was hoping that Glassfish v3 was going to support other type of table column field such as collection type but it turn out not to support EJB altogether. It would be ideal to have a JPA that support this functionality which will eliminiate some cross table matching resulting in much simpler codes.

I am running JDK1.6.07, Glassfish v2r2 together with MySQL, Netbeans on Windows XP.

Any assistance would be greatly appreciated.

Many thanks,

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!