Hello,
Similar to
http://forum.hibernate.org/viewtopic.ph ... 52#2359052 (a little simpler), I am trying to find a way to map the following classes.
In a nutshell, a car can be owned by a person or an enterprise, and needs to know its owner.
Can anyone help? Thanks in advance
Code:
@MappedSuperclass
class AbstractModel {
@EmbeddedId
private UUID id = UUID.randomUUID();
}
interface CarOwner {
}
@Entity
class Person extends AbstractModel implements CarOwner {
@OneToMany
List<Car> cars = new ArrayList<Car>();
}
@Entity
class Enterprise extends AbstractModel implements CarOwner {
@OneToMany
List<Car> cars = new ArrayList<Car>();
}
@Entity
class Car {
@ManyToOne
private CarOwner owner;
}
[/code]