-1

I'm having trouble deciding how to represent a 'ReleaseDate' field in a 'Movie' entity in JPA. Take for example this movie. The class fields would look something like this:

@Entity
public class Movie {
   private Long id;
   private String name;
   private Director director;
   private List<Writer> writers;
   private List<Actor> actors;
   private List<ReleaseDate> releaseDates;
}

//@Entity ?
class ReleaseDate {
    private String northAmericanReleaseDate;
    private String europeanReleaseDate;
    private String asianReleaseDate;
    // add more locations here
}

If the movie can have mutliple release dates I'm not quite sure how to represent them. The above is what I have so far, and if a movie is not released in a location it will be null, implying not released in that location.

The bigger question is that I don't think ReleaseDate should be an entity/class as I don't think it warrants a row in a table with it's own ID. What's the best strategy here? Thanks.

Community
  • 1
  • 1
Alan Smith
  • 1,069
  • 4
  • 19
  • 23
  • First, you should use `id`, not `Id`. Second, you shoulr use LocalDate to represent a date, rather than a String. Regarding your question, you should instead use a Map, or a Set, where LocatedReleaseDate would be an entity (or an Embeddable) with a Location and a LocalDate. – JB Nizet Sep 12 '17 at 22:08
  • [Embeddable](https://stackoverflow.com/questions/21143707/what-is-difference-between-entity-and-embeddable) is probably what I'm after. Thanks. – Alan Smith Sep 12 '17 at 22:30

2 Answers2

0

I think the data model is not correct (and your question doesn't have anything to do with JPA). Maybe I am wrong, but I assume, the release date is linked to a movie and a continent (Europe, America, Asia), or any other geographical place, right? Then the event Release should be an entity with members Movie, Date, Location/continent,country,whatever. (Movie and Location should be unique).

It doesn't make sense to have one release date and for each location one member field, having them nulls. Instead, the locations should be generic.

fairtrax
  • 416
  • 2
  • 8
  • It does have to do with JPA as it comes down to how I represent the entity in tables. – Alan Smith Sep 12 '17 at 22:26
  • yes, but I mean technically the architecture of data model is one issue, the technical solution of persisting is another issue. Here the problem isn't any technical issue of JPA, but the question, how to design the data model. Then it can be persisted via files, mongoDb, jdbc, or JPA, doesn't matter. – fairtrax Sep 12 '17 at 23:27
0
enum ReleaseLocation {
  NorthAmerica, Europe, Asia;
}

class ReleaseDate {
  private String releaseDate;
  private ReleaseLocation releaseLocation;
}

What about something like this?

Rick Ridley
  • 573
  • 2
  • 9