have a project set up like the following:
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
@XmlRootElement(name="employee")
@XmlSeeAlso([EmployeeDesiredSkill.class, EmployeeDesiredTool.class, EmployeeAreaOfExpertise.class, Project.class, Education.class])
@XmlAccessorType(XmlAccessType.NONE)
class Employee implements Comparable
{
static hasMany = [employeeDesiredSkills:EmployeeDesiredSkill]
@XmlElement
String name
@XmlElement
List<EmployeeDesiredSkill> employeeDesiredSkills = new ArrayList<EmployeeDesiredSkill>();
}
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@XmlAccessorType(XmlAccessType.NONE)
class EmployeeDesiredSkill implements Comparable
{
boolean _deleted
@XmlElement
Skill skill
static belongsTo = [employee:Employee, skill:Skill]
}
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@XmlAccessorType(XmlAccessType.FIELD)
class Skill implements Comparable
{
static hasMany = [roleSkills:RoleSkill, employeeDesiredSkills:EmployeeDesiredSkill]
boolean _deleted
static transients = ['_deleted']
@XmlAttribute
String name
}
When I try to do the XML marshaling of this setup, I get valid values foe Employee, but all of the skills come back empty, like so:
<employee name = "Joe">
<employeeDesiredSkills>
<skill name="">
<_deleted>false</_deleted>
</skill>
</employeeDesiredSkills>
<employeeDesiredSkills>
<skill name="">
<_deleted>false</_deleted>
</skill>
</employeeDesiredSkills>
<employeeDesiredSkills>
<skill name="">
<_deleted>false</_deleted>
</skill>
</employeeDesiredSkills>
<employeeDesiredSkills>
<skill name="">
<_deleted>false</_deleted>
</skill>
</employeeDesiredSkills>
<employeeDesiredSkills>
<skill name="">
<_deleted>false</_deleted>
</skill>
</employeeDesiredSkills>
In other words - name is never returned from the Skill objects. I think Employee must know how many employeeDesiredSkills are in the list (since 5 of them show up), but for some reason can not get the values in the Skill class.
What can I do to fix this? In my controller, if I do the following:
def employee = Employee.get(session.empid);
for(esd in employee.getEmployeeDesiredSkills()){println "EmployeeDesiredSkill:" + esd}
I get the full list of desired skills printed (5 of them), so I know the values are in the database already.
To me it seems like the EmployeeDesiredSkill class doesnt know which employee to return the skills for, but I am not sure if that is the right thinking or not. I dont really want to add a belongsTo = Employee to my Skills class, because I want those skills to possibly be used by other employees as well.