I have a web service running EclipseLink. I have generated some Java classes with NetBeans that are based on the database schema ("Entity classes from database...").
My problem is about two classes called Person.java and Group.java that have been generated by NetBeans based on the database schema. Person.java and Group.java is part of the JAR file "MyLib.jar"
In Group.java, I have this code (among other code):
@Column(name = "groupName")
private String groupName;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "group")
private Collection<Person> personCollection;
public String setGroupName(String groupName) {
this.groupName = groupName;
}
public String getGroupName(){
return groupName;
}
@XmlTransient
public Collection<Person> getPersonCollection() {
return personCollection;
}
public void setPersonCollection(Collection<Person> personCollection) {
this.personCollection = personCollection;
}
I have two different applications that include the "MyLib.jar". One is the web-service itself and the other is a client that connects to the web-service. The client also, of course, includes the web service interface JAR.
In the client I create a collection of Persons like this and then send the group instance to the web-service:
Collection<Person> persons = new ArrayList<Person>();
Person person = new Person();
person.setName("Peter");
persons.add(person);
group.setName("GroupName");
group.setPersonCollection(persons);
System.out.print(persons); // prints the instance and its content
webserviceInstance.setGroup(group);
The really strange thing is that in the web-service method setGroup
, the collection is null!
@Override
public void setGroup(Group group) {
System.out.print(group.getGroupName()); // prints "GroupName"
System.out.print(group.getPersonCollection()); // prints null meaning the instance is null
...
}
I simply cannot understand why the collection is null in the web service but not in the client. Am I doing anything wrong?