Question

I'm working at a place where the convention for member variable is "m_(name)" and the getters and setters are "(get/set)Name".

So, I have:

AccidentName.java

@XmlInverseReference(mappedBy = "m_occupants")
public AccidentVehicle getAccidentVehicleRecord() {
    ...
}

AccidentVehicle.java

@XmlElementWrapper( name="Occupants" )
@XmlElements( @XmlElement( name="AccidentName" ) )
public Set<AccidentName> getOccupants() {
    return m_occupants;
}

I'm trying to define inverse references using Moxy's annotation but I'm getting errors like this:

Exception [EclipseLink-59] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The instance variable [accidentVehicleRecord] is not defined in the domain class [net.denali.inpursuit.rms.data.persistent.accident.AccidentName], or it is not accessible.
Internal Exception: java.lang.NoSuchFieldException: accidentVehicleRecord
Mapping: org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping[accidentVehicleRecord]
Descriptor: XMLDescriptor(net.denali.inpursuit.rms.data.persistent.accident.AccidentName --> [DatabaseTable(AccidentName), DatabaseTable(AuditableEntity)])

The getter/setter is (get/set)AccidentVehicleRecord, but the member variable is m_accidentVehicleRecord.

Do I need to always specify both side of an inverse? Do I need to have methods name exactly matching pattern get(variable name)?

Was it helpful?

Solution

I have been able to recreate the issue you are seeing. I have entered a bug here:

Work Around

You could switch to use field access.

AccidentVechicle

import java.util.*;
import javax.xml.bind.annotation.*;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class AccidentVehicle {

    @XmlElementWrapper( name="Occupants" )
    @XmlElements( @XmlElement( name="AccidentName" ) )
    private Set<AccidentName> m_occupants = new HashSet<AccidentName>();

    public Set<AccidentName> getOccupants() {
        return m_occupants;
    }

}

AccidentName

import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;

@XmlAccessorType(XmlAccessType.FIELD)
public class AccidentName {

    @XmlInverseReference(mappedBy = "occupants")
    private AccidentVehicle m_accidentVehicleRecord;

    public AccidentVehicle getAccidentVehicleRecord() {
        return m_accidentVehicleRecord;
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top