@XmlInverseReference with interface field [message #1020523] |
Mon, 18 March 2013 07:17  |
Eclipse User |
|
|
|
Hello,
I was wondering if the @XmlInverseReference also works on entities with fields that refer to an interface since the @XmlElement gives an instantiation error for those types of fields.
I am using MOXy with Spring and follow the instructions here http://wiki.eclipse.org/EclipseLink/Examples/MOXy/Spring/JAXBAnnotation. I have for example a Sensor class that has a SensorReading field, which is an interface.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "sensor")
@PrimaryKeyJoinColumn(name = "sensor_id")
public class Sensor extends LowLevelEntity implements Serializable
{
@XmlInverseReference(mappedBy = "sensor")
@OneToOne(targetEntity = ConcreteSensorReading.class, cascade = CascadeType.ALL,
fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "concrete_sensor_reading_id")
protected SensorReading sensorReading;
// getters and setters
}
The ConcreteSensorReading class is an implementatition of the SensorReading interface
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "concrete_sensor_reading")
public class ConcreteSensorReading implements SensorReading
{
@XmlID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "concrete_sensor_reading_id")
private long uuid;
@XmlInverseReference(mappedBy = "sensorReading")
@XmlElement
@OneToOne(mappedBy = "sensorReading", fetch = FetchType.EAGER )
protected Sensor sensor;
// getters and setters
}
The SensorReading interface is annotated like so
@XmlRootElement
@XmlSeeAlso(ConcreteSensorReading.class)
public interface SensorReading
{
public Sensor getSensor();
public void setSensor(Sensor sensor);
}
Using this configuration I get no errors but the ConcreteSensorReading is not mapped to the xml when I marshall the Sensor object using the XmlHelper save method. Is there a correct way of doing this? I'm very new to MOXy and I might not have understood how this must be done. Thank you for your help.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09843 seconds