posted 12 years ago
Hi ranchers,
I'm struggeling with a mapping strategy for a couple of entities. Note that I'm using JPA 2.0 and Hibernate 3.5.6. The application serves as a learing app for this frameworks. This is the scenario I've implemented:
- a person can be an actor or a director
- both of the previous types can participate in one or multiple (different) movies
- a movie can include one or multiple actors and one or more directors
- and what's giving me a headache: an actor and a director can be one and the same person!
This is what my mapping is looking like:
I've not included the getters and setters, plus the builder classes to easily create a director or an actor. Just for now, suppose I've created an actor like this:
As this is the first entity to be saved, an identifier with value 1 will be generated. Now here comes the part I'm struggling with. This actor should also be known as an director of several other movies. The (dirty) solution I was thinking about, was to copy all the values of the actor into the director, including the identifer. But because the identifier is auto generated when an entity is persisted, the given identifier will be overridden by a new generated id. Thus the director and the actor are two different persons in the database. Does anyone know a clean sollution for this? Should I map my entities differently? Should I choose another id generation strategy? Thanks for sharing your thoughts!
SCJP 1.5, SCWCD 1.4, SCBCD 5