|
Re: @XmlInverseReference with interface field [message #1021246 is a reply to message #1020523] |
Tue, 19 March 2013 18:19 |
|
You could do the following:
Sensor
Using EclipseLink 2.5.0 (you can get a nightly build from: http://www.eclipse.org/eclipselink/downloads/nightly.php) you could use an @XmlInverseReference with an @XmlElement to specify the concrete type.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "sensor")
@PrimaryKeyJoinColumn(name = "sensor_id")
public class Sensor extends LowLevelEntity implements Serializable
{
@XmlInverseReference(mappedBy = "sensor")
@XmlElement(type=ConcreteSensorReading.class)
@OneToOne(targetEntity = ConcreteSensorReading.class, cascade = CascadeType.ALL,
fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "concrete_sensor_reading_id")
protected SensorReading sensorReading;
// getters and setters
}
ConcreteSensorReading
@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;
@Override
public Sensor getSensor() {
return sensor;
}
@Override
public void setSensor(Sensor sensor) {
this.sensor = sensor;
}
// getters and setters
}
SensorReading
You shouldn't have any mappings on the interface itself (see: http://blog.bdoughan.com/2011/05/jaxb-and-interface-fronted-models.html).
public interface SensorReading
{
public Sensor getSensor();
public void setSensor(Sensor sensor);
}
For More Information
- http://blog.bdoughan.com/2013/03/moxys-xmlinversereference-is-now-truly.html
|
|
|
|
Powered by
FUDForum. Page generated in 0.23509 seconds