"Java Persistence 2.0, Final Release" on page 404 has the following example:
Example 3: One-to-one association from an embeddable class to another entity.
@Entity
public class Employee {
@Id int id;
@Embedded LocationDetails location;
...
}
@Embeddable
public class LocationDetails {
int officeNumber;
@OneToOne ParkingSpot parkingSpot;
...
}
@Entity
public class ParkingSpot {
@Id int id;
String garage;
@OneToOne(mappedBy="location.parkingSpot") Employee assignedTo;
...
}
I would like to have multiple LocationDetails inside Employee:
@Entity
public class Employee {
@Id int id;
@ElementCollection
@CollectionTable(name="EMP_LOCATION")
Map<String, LocationDetails> locations;
...
}
How the entity ParkingSpot has to be changed to point back to embeddable LocationDetails inside the collection table EMP_LOCATION.
Should be
@OneToOne(mappedBy="location.parkingSpot") Employee assignedTo;
replaced be by @ElementCollection ?
Thank You!